Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.google.androidbrowserhelper.trusted;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;
import androidx.browser.trusted.TrustedWebActivityCallbackRemote;
import androidx.core.app.ActivityCompat;

public class ContactPermissionRequestActivity extends Activity {

private static final String TAG = "stomoki ContactReq";

private static final String[] CONTACT_PERMISSION = {Manifest.permission.READ_CONTACTS};

private static final String CONTACT_PERMISSION_RESULT = "contactPermissionResult";

private static final String EXTRA_RESULT_RECEIVER = "EXTRA_RESULT_RECEIVER";
private static final String EXTRA_PERMISSIONS = "EXTRA_PERMISSIONS";
private static final String EXTRA_GRANT_RESULTS = "EXTRA_GRANTED_RESULT";

private Messenger mMessenger;

public static void requestContactPermisson(Context context,
TrustedWebActivityCallbackRemote callback) {
Log.d(TAG, "Permission request started");

Handler handler = new Handler(Looper.getMainLooper(), message -> {
Bundle data = message.getData();
Log.d(TAG, "Intent result: " + data);

Bundle result = new Bundle();

result.putBoolean(CONTACT_PERMISSION_RESULT, false);

String[] permissions = data.getStringArray(EXTRA_PERMISSIONS);
int[] grantedResult = data.getIntArray(EXTRA_GRANT_RESULTS);

for (int i = 0; i < permissions.length; i++) {
if (permissions[i].equals(CONTACT_PERMISSION[0])) {
result.putBoolean(CONTACT_PERMISSION_RESULT,
grantedResult[i] == PackageManager.PERMISSION_GRANTED);
break;
}
}

try {
callback.runExtraCallback(
ContactDelegationExtraCommandHandler.COMMAND_CHECK_CONTACT_PERMISSION, result);
} catch (RemoteException e) {
e.printStackTrace();
}

return true;
});

final Messenger messenger = new Messenger(handler);
Intent intent = new Intent(context, ContactPermissionRequestActivity.class);
intent.putExtra(EXTRA_PERMISSIONS, CONTACT_PERMISSION);
intent.putExtra(EXTRA_RESULT_RECEIVER, messenger);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

String[] permissions = getIntent().getStringArrayExtra(EXTRA_PERMISSIONS);
mMessenger = getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER);
ActivityCompat.requestPermissions(this, permissions, 0);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
Message message = new Message();
Bundle data = new Bundle();
data.putStringArray(EXTRA_PERMISSIONS, permissions);
data.putIntArray(EXTRA_GRANT_RESULTS, grantResults);
message.setData(data);
try {
mMessenger.send(message);
} catch (RemoteException e) {
e.printStackTrace();
} finally {
finish();
}
}
}
1 change: 1 addition & 0 deletions demos/twa-contact-delegation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions demos/twa-contact-delegation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id 'com.android.application'
}

android {
namespace 'com.google.androidbrowserhelper.demos.twa_contact_delegation'

defaultConfig {
applicationId "com.google.androidbrowserhelper.demos.twa_contact_delegation"
minSdkVersion 21
compileSdk 36
targetSdkVersion 31
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

buildTypes {
release {
minifyEnabled false
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':androidbrowserhelper')
}
116 changes: 116 additions & 0 deletions demos/twa-contact-delegation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.androidbrowserhelper.demos.twa_contact_delegation">

<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<meta-data
android:name="asset_statements"
android:resource="@string/asset_statements" />

<activity
android:name="com.google.androidbrowserhelper.trusted.LauncherActivity"
android:label="@string/app_name"
android:exported="true">
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://whatpwacando.today/contacts" />

<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
android:resource="@color/colorPrimary" />

<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR_DARK"
android:resource="@color/colorPrimaryDark" />

<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
android:resource="@color/navigationColor" />

<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR_DARK"
android:resource="@color/navigationColorDark" />

<meta-data
android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"
android:resource="@drawable/splash" />

<meta-data
android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
android:resource="@color/backgroundColor" />

<meta-data
android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"
android:value="300" />

<meta-data
android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"
android:value="@string/provider_authority" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="whatpwacando.today" />
</intent-filter>

</activity>

<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />

<activity android:name="com.google.androidbrowserhelper.trusted.ContactPermissionRequestActivity" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="@string/provider_authority"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

<service
android:name=".ContactDelegationService"
android:enabled="true"
android:exported="true">

<meta-data
android:name="android.support.customtabs.trusted.SMALL_ICON"
android:resource="@drawable/ic_notification_icon" />

<intent-filter>
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.androidbrowserhelper.demos.twa_contact_delegation;


import com.google.androidbrowserhelper.trusted.ContactDelegationExtraCommandHandler;
import com.google.androidbrowserhelper.trusted.DelegationService;

public class ContactDelegationService extends DelegationService {

public ContactDelegationService() {
registerExtraCommandHandler(new ContactDelegationExtraCommandHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="26.086956"
android:viewportHeight="26.086956"
android:tint="#FFFFFF">
<group android:translateX="1.0434783"
android:translateY="1.0434783">
<path
android:fillColor="#FF000000"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
</group>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading