Update PushAPI authenticator to work with new Discovery API.

Add dummy certificates to PushApi authenticator and test apps to
simplify their usage:

Bug: 33046496
Test: manual tests.
Change-Id: I94e5fa1ac430da77c0f74ed87bd12467a3ba76b8
This commit is contained in:
Dmitry Dementyev
2016-12-22 12:50:37 -08:00
parent 69c24214d3
commit b99e8db305
20 changed files with 327 additions and 138 deletions

View File

@@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current
LOCAL_DEX_PREOPT := false LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert
include $(BUILD_PACKAGE) include $(BUILD_PACKAGE)
# Use the following include to make our test apk. # Use the following include to make our test apk.

View File

@@ -26,6 +26,12 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<receiver android:name="com.example.android.pushapiauthenticator.MessageReceiver">
<intent-filter>
<action android:name="android.accounts.action.ACCOUNTS_LISTENER_PACKAGE_INSTALLED"/>
</intent-filter>
</receiver>
<service <service
android:name=".MyAccountAuthenticatorService" android:name=".MyAccountAuthenticatorService"
android:exported="true"> android:exported="true">

Binary file not shown.

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID/TCCAuWgAwIBAgIJAKRuYMXiytGmMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD
VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g
VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE
AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe
Fw0xNzAxMDUyMTE1MDNaFw00NDA1MjMyMTE1MDNaMIGUMQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEQMA4G
A1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHQW5kcm9p
ZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBALtTbsz8TuSvlCHQW5F6eQq/4OBtb7SyZolj
/H/gmYdda8Qr0ImHczh+Vfrq++lNDhglzfiaQ8x4bwrkEomPeqaGCUtDaJDN2cXl
ajc8Fgbw/5mSRzekx9JincMwUHFOkg8DE7hTOTJqR3HCBF4XAIWPxvWsdHUJ4s6C
OEi+akQSnWIj3Zitptf6Pip9kx3Rl+234LJIyCxYYicDBhx5dVbENzUJSL5ImVzf
gGzh8Zqim93PmsU9b8BhMi85rhj4HhDvJ3+1Nfdh99C8w24YRobDeuyy3sVxxeyZ
pE3Le3qkDu10IFmdEKe68QmT0Ye/Qo4zb8rBXGp9HI0kl2qUfS8CAwEAAaNQME4w
HQYDVR0OBBYEFDcLryrRgTHXTGjOcO1e4FsToMIVMB8GA1UdIwQYMBaAFDcLryrR
gTHXTGjOcO1e4FsToMIVMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
ALZ87eW23vF6rn6vOHi68vZC7bNo/DS4z8cMC6E9aafLWyJinBE2HzchOuWKwcO7
YkW+ODRN0EgSTO8xhgoEUzOEVaB7ysT5DUJD7Vck0zpYyy/+whenpfD6RombH4dM
2lsiuKGDqy/+waPq9KkiiSSCaq4LbMKVDvYAVpmaWDCXhSaczS8foNE7+d3u2o9K
84MuHFgJGGNAcZEVXYofuhv+LbmYHzMmojPTW9n3EEWIUR4fG5+fU2v1YZPgEi3b
tQ1L+vov9CIU+83bPLvpZJ+Rv1y4qMIF1eCgE8ea+0Jz+9KD3wHPmX9aUryFQQaC
NJ70c2gKCJ8hi0pPlWQZ5Ec=
-----END CERTIFICATE-----

View File

@@ -146,7 +146,7 @@
<RadioGroup <RadioGroup
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="220dp" android:layout_height="280dp"
android:id="@+id/optionsGroup" android:id="@+id/optionsGroup"
android:layout_below="@+id/textView11" android:layout_below="@+id/textView11"
android:layout_alignParentLeft="true"> android:layout_alignParentLeft="true">
@@ -154,15 +154,22 @@
<RadioButton <RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="ADD VISIBILITY" android:text="SET VISIBLE (MANAGED)"
android:id="@+id/addButton" android:id="@+id/visibleButton"
android:checked="false" /> android:checked="false" />
<RadioButton <RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="REMOVE VISIBILITY" android:text="SET NOT_VISIBLE (MANAGED)"
android:id="@+id/removeButton" android:id="@+id/notVisibleButton"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SET NOT_VISIBLE"
android:id="@+id/forcedNotVisibleButton"
android:checked="false" /> android:checked="false" />
<RadioButton <RadioButton
@@ -186,6 +193,13 @@
android:id="@+id/addAccountButtonWithUid" android:id="@+id/addAccountButtonWithUid"
android:checked="false" /> android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RENAME ACCOUNT"
android:id="@+id/renameAccount"
android:checked="false" />
<RadioButton <RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -1,17 +1,15 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2016 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* you may not use this file except in compliance with the License. * in compliance with the License. You may obtain a copy of the License at
* You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software distributed under the License
* distributed under the License is distributed on an "AS IS" BASIS, * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * or implied. See the License for the specific language governing permissions and limitations under
* See the License for the specific language governing permissions and * the License.
* limitations under the License.
*/ */
package com.example.android.pushapiauthenticator; package com.example.android.pushapiauthenticator;
@@ -36,6 +34,8 @@ import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.HashMap;
public class MainActivity extends Activity { public class MainActivity extends Activity {
private static AccountManager am; private static AccountManager am;
@@ -67,14 +67,14 @@ public class MainActivity extends Activity {
final Button selectOption = (Button) findViewById(R.id.selectoptionbutton); final Button selectOption = (Button) findViewById(R.id.selectoptionbutton);
final TextView authStatus = (TextView) findViewById(R.id.authenticatorstatus); final TextView authStatus = (TextView) findViewById(R.id.authenticatorstatus);
final Toast hitGet = Toast.makeText(getApplicationContext(), final Toast hitGet =
"Hit the GET Button!", Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Hit the GET Button!", Toast.LENGTH_SHORT);
final Toast enterUidWarning = Toast.makeText(getApplicationContext(), final Toast enterUidWarning =
"Enter a UID!", Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Enter a UID!", Toast.LENGTH_SHORT);
final Toast chooseAccountWarning = Toast.makeText(getApplicationContext(), final Toast chooseAccountWarning =
"Choose an Account!", Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Choose an Account!", Toast.LENGTH_SHORT);
final Toast chooseOptionWarning = Toast.makeText(getApplicationContext(), final Toast chooseOptionWarning =
"Choose an Option!", Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Choose an Option!", Toast.LENGTH_SHORT);
final String ACCOUNT_PASSWORD = "some password"; final String ACCOUNT_PASSWORD = "some password";
final Bundle ACCOUNT_BUNDLE = new Bundle(); final Bundle ACCOUNT_BUNDLE = new Bundle();
@@ -85,8 +85,8 @@ public class MainActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Welcome to Auth App. \nPlease make sure you have: \n\n1. Test App 1\n" builder.setMessage("Welcome to Auth App. \nPlease make sure you have: \n\n1. Test App 1\n"
+"\n2. Test App 2 \n\ninstalled for the demo. These applications" + + "\n2. Test App 2 \n\ninstalled for the demo. These applications"
" together provide tests, use cases, and proof of concept of Push API!\n") + " together provide tests, use cases, and proof of concept of Push API!\n")
.setTitle("WELCOME") .setTitle("WELCOME")
.setPositiveButton("Okay", new DialogInterface.OnClickListener() { .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override @Override
@@ -101,16 +101,16 @@ public class MainActivity extends Activity {
getAllRequestingApps.setOnClickListener(new View.OnClickListener() { getAllRequestingApps.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
int[] allRequestedUids = am.getRequestingUidsForType(getApplicationContext() int[] allRequestedUids = null;
.getPackageName()); // TODO remove uid part
// am.getRequestingUidsForType(getApplicationContext().getPackageName());
if (allRequestedUids != null) { if (allRequestedUids != null) {
StringBuilder uidMasterString = new StringBuilder(); StringBuilder uidMasterString = new StringBuilder();
StringBuilder packageMasterString = new StringBuilder(); StringBuilder packageMasterString = new StringBuilder();
for (int i = 0; i < allRequestedUids.length; i++) { for (int i = 0; i < allRequestedUids.length; i++) {
uidMasterString.append(allRequestedUids[i] + ",\n\n"); uidMasterString.append(allRequestedUids[i] + ",\n\n");
packageMasterString.append(getPackageManager(). packageMasterString.append(
getNameForUid(allRequestedUids[i]) getPackageManager().getNameForUid(allRequestedUids[i]) + ",\n\n");
+ ",\n\n");
} }
if (uidMasterString.length() > 0) { if (uidMasterString.length() > 0) {
getAllRequesting3pUids.setText(uidMasterString); getAllRequesting3pUids.setText(uidMasterString);
@@ -132,9 +132,7 @@ public class MainActivity extends Activity {
selectOption.setOnClickListener(new View.OnClickListener() { selectOption.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//TODO update Authenticator once AccountManager API is updated /*Account currentAccount = terraAccount;
/*
Account currentAccount = terraAccount;
int checkedAccount = accountChooser.getCheckedRadioButtonId(); int checkedAccount = accountChooser.getCheckedRadioButtonId();
int checkedOption = optionChooser.getCheckedRadioButtonId(); int checkedOption = optionChooser.getCheckedRadioButtonId();
if (uidChooser.getText().length() == 0) { if (uidChooser.getText().length() == 0) {
@@ -154,53 +152,83 @@ public class MainActivity extends Activity {
} }
String uidstr = uidChooser.getText().toString(); String uidstr = uidChooser.getText().toString();
int uid = Integer.parseInt(uidstr); int uid = Integer.parseInt(uidstr);
if (checkedOption == R.id.addButton) { if (checkedOption == R.id.visibleButton) {
am.makeAccountVisible(currentAccount, uid); am.setAccountVisibility(currentAccount, uid,
Toast.makeText(getApplicationContext(), "Giving Visibility of " + AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
currentAccount.name + " to " + Toast.makeText(getApplicationContext(),
getPackageManager().getNameForUid(uid), "Giving visibility of " + currentAccount.name + " to "
+ getPackageManager().getNameForUid(uid),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.removeButton) { } else if (checkedOption == R.id.notVisibleButton) {
am.removeAccountVisibility(currentAccount, uid); am.setAccountVisibility(currentAccount, uid,
Toast.makeText(getApplicationContext(), "Removing Visibility of " + AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
currentAccount.name + " to " + Toast.makeText(getApplicationContext(),
getPackageManager().getNameForUid(uid), "Removing visibility of " + currentAccount.name + " to "
+ getPackageManager().getNameForUid(uid),
Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.forcedNotVisibleButton) {
am.setAccountVisibility(currentAccount, uid,
AccountManager.VISIBILITY_NOT_VISIBLE);
Toast.makeText(getApplicationContext(),
"Removing visibility (not managed) of " + currentAccount.name
+ " to " + getPackageManager().getNameForUid(uid),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.getButton) { } else if (checkedOption == R.id.getButton) {
Toast.makeText(getApplicationContext(), "Is " + currentAccount.name + Toast.makeText(getApplicationContext(),
" visible to " + getPackageManager().getNameForUid(uid) + "?\n" + "Is " + currentAccount.name + " visible to "
am.isAccountVisible(currentAccount, uid), Toast.LENGTH_SHORT) + getPackageManager().getNameForUid(uid) + "?\n"
.show(); + am.getAccountVisibility(currentAccount, uid),
Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.addAccountButton) { } else if (checkedOption == R.id.addAccountButton) {
Toast.makeText(getApplicationContext(), "Adding account explicitly!" Toast.makeText(getApplicationContext(),
"Adding account explicitly!"
+ am.addAccountExplicitly(currentAccount, null, null), + am.addAccountExplicitly(currentAccount, null, null),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.addAccountButtonWithUid) { } else if (checkedOption == R.id.addAccountButtonWithUid) {
int[] uidsToAdd = new int[] {uid}; HashMap<Integer, Integer> uidsAndVisibility = new HashMap<>();
Toast.makeText(getApplicationContext(), "Adding account explicitly!" uidsAndVisibility.put(uid, AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
+ am.addAccountExplicitly(currentAccount, null, null, uidsToAdd) Toast.makeText(getApplicationContext(),
"Adding account explicitly!"
+ am.addAccountExplicitly(currentAccount, null, null,
uidsAndVisibility)
+ " TO: " + getPackageManager().getNameForUid(uid) + "!", + " TO: " + getPackageManager().getNameForUid(uid) + "!",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.removeAccount) { } else if (checkedOption == R.id.removeAccount) {
Toast.makeText(getApplicationContext(), "Removing account explicitly!" Toast.makeText(getApplicationContext(),
"Removing account explicitly!"
+ am.removeAccountExplicitly(currentAccount), + am.removeAccountExplicitly(currentAccount),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else if (checkedOption == R.id.renameAccount) {
try {
AccountManagerFuture<Account> accountRenameFuture = am.renameAccount(
currentAccount, currentAccount.name + "1", null, null);
Account renamedAccount = accountRenameFuture.getResult();
Toast.makeText(getApplicationContext(),
"New account name " + renamedAccount, Toast.LENGTH_SHORT)
.show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Exception" + e, Toast.LENGTH_SHORT)
.show();
}
} }
StringBuilder masterString = new StringBuilder(); StringBuilder masterString = new StringBuilder();
String uidMasterString = getAllRequesting3pUids.getText().toString(); String uidMasterString = getAllRequesting3pUids.getText().toString();
int[] allUids = am.getRequestingUidsForType(getApplicationContext(). int[] allUids = null;
getPackageName()); //am.getRequestingUidsForType(getApplicationContext().getPackageName());
if (allUids != null) { if (allUids != null) {
for (int i = 0; i < allUids.length; i++) { for (int i = 0; i < allUids.length; i++) {
masterString.append(allUids[i] + "\n"); masterString.append(allUids[i] + "\n");
if (am.isAccountVisible(terraAccount, allUids[i])) { if (am.getAccountVisibility(terraAccount,
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
masterString.append(terraAccount.name + ","); masterString.append(terraAccount.name + ",");
} }
if (am.isAccountVisible(aquaAccount, allUids[i])) { if (am.getAccountVisibility(aquaAccount,
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
masterString.append(aquaAccount.name + ","); masterString.append(aquaAccount.name + ",");
} }
if (am.isAccountVisible(ventusAccount, allUids[i])) { if (am.getAccountVisibility(ventusAccount,
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
masterString.append(ventusAccount.name); masterString.append(ventusAccount.name);
} }
masterString.append("\n"); masterString.append("\n");
@@ -208,13 +236,10 @@ public class MainActivity extends Activity {
} }
if (masterString.length() > 0) { if (masterString.length() > 0) {
authStatus.setText(masterString); authStatus.setText(masterString);
} } else {
else {
authStatus.setText("----"); authStatus.setText("----");
} }
} }*/
*/
} }
}); });
} }}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.example.android.pushapiauthenticator;
import android.accounts.Account;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class MessageReceiver extends BroadcastReceiver {
private static final String TAG = "PushApiAuthenticator";
public void onReceive(Context context, Intent intent) {
if (intent.getAction()
.equals("android.accounts.action.ACCOUNTS_LISTENER_PACKAGE_INSTALLED")) {
String newPackage = intent.getStringExtra("android.intent.extra.PACKAGE_NAME");
Log.i(TAG, "new app is installed " + newPackage);
Toast.makeText(context, "new app is installed" + newPackage, Toast.LENGTH_LONG).show();
}
}
}

View File

@@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current
LOCAL_DEX_PREOPT := false LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert
include $(BUILD_PACKAGE) include $(BUILD_PACKAGE)
# Use the following include to make our test apk. # Use the following include to make our test apk.

View File

@@ -18,6 +18,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.pushapithirdpartyone"> package="com.example.android.pushapithirdpartyone">
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-sdk android:minSdkVersion="1"
android:targetSdkVersion="10001"
android:maxSdkVersion="11000" />
<application android:label="3P App 1" android:icon="@drawable/push"> <application android:label="3P App 1" android:icon="@drawable/push">
<activity android:name="MainActivity"> <activity android:name="MainActivity">
<intent-filter> <intent-filter>
@@ -27,7 +30,7 @@
</activity> </activity>
<receiver android:name="com.example.android.pushapithirdpartyone.MessageReceiver"> <receiver android:name="com.example.android.pushapithirdpartyone.MessageReceiver">
<intent-filter> <intent-filter>
<action android:name="android.accounts.NEW_ACCOUNT_VISIBLE"/> <action android:name="android.accounts.action.VISIBLE_ACCOUNTS_CHANGED"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<meta-data <meta-data

Binary file not shown.

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID/TCCAuWgAwIBAgIJAJQhygyzfNTkMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD
VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g
VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE
AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe
Fw0xNzAxMDUyMTE1MThaFw00NDA1MjMyMTE1MThaMIGUMQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEQMA4G
A1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHQW5kcm9p
ZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBANGi5LzphWNe/XUJ4xrZQmES4eg97nbt2aN/
6Anw1C/7fNkYhMaPXDmju/V4DquCRDAlihRJslreusq/3JpZ4hX/F1xcjBF2sPda
hGQf4LSJRZG7mxCjekRH9W6vUMsALQ2ckhx/QONWayoyVBezvBwmzfOjVXMpmTwt
qGOv4Kq/YRP/Og1A4+QbI9YmXitknjDSXizExlU7hrb0HYrbQ8PGMPZuKh2+f6uN
EVUc7/OWlHeTb1QEbohHIxCFTmfgh37RiQ+oH65Hl3w2ihwIGfarsEXg/aVKxZAE
8T5JhNk2X5kdLdQx2cl8YT0w353Ppv+LU+sIpvyqXA1tc4zYCQ0CAwEAAaNQME4w
HQYDVR0OBBYEFMTJcp+DkufKA0VNM2d7FykV/uXBMB8GA1UdIwQYMBaAFMTJcp+D
kufKA0VNM2d7FykV/uXBMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
AMBqip+t6vvUTU/lziiUQyboJ4EP79776AvZRIP+V61aNnQvDHYI0Ok99i9+auJS
YtkWu+V53AMwEEzXGJsZVNCjdHjeWZwCbncZI/nmkHIhW1gHXmJqwwm5H2iChXDI
3HAZL5s6+T23OZV/T91q1ZWAnTBTTv7mJBqcrerxrrUHw5pWEwMmwbfS87h1KlEj
fQuQeldvmMn5jc+fn0tL09EdgbYQ+3HXvjmVcNRQyZe0yFSDESBv19P1mKDFyjcp
8KqTr+3eaDkRx0gaIjGO1rjB6rCncN5nlA1Xeeu/ECFZO39PYh2GfPyhIYOHKeDs
8D6CT+FwXp7PxXqJEmwWjC0=
-----END CERTIFICATE-----

View File

@@ -41,6 +41,7 @@ import android.widget.ToggleButton;
public class MainActivity extends Activity { public class MainActivity extends Activity {
private static AccountManager am; private static AccountManager am;
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -50,15 +51,14 @@ public class MainActivity extends Activity {
final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered); final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered);
final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts); final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts);
final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts); final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts);
final Toast notifOn = Toast.makeText(getApplicationContext(), "Notifs Turned On!", final Toast notifOn =
Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Notifs Turned On!", Toast.LENGTH_SHORT);
final Toast notifOff = Toast.makeText(getApplicationContext(), "Notifs Turned Off!", final Toast notifOff =
Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Notifs Turned Off!", Toast.LENGTH_SHORT);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Welcome to Test App 1.\nPlease make sure you have:\n\n1. Test App 2\n" builder.setMessage("Welcome to Test App 1.\nPlease make sure you have:\n\n1. Test App 2\n"
+ "\n2. Auth App \n\ninstalled for the demo. These applications together provide" + + "\n2. Auth App \n\ninstalled for the demo. These applications together provide"
" tests, use cases, and proof of concept of Push API!\n") + " tests, use cases, and proof of concept of Push API!\n").setTitle("WELCOME")
.setTitle("WELCOME")
.setPositiveButton("Okay", new DialogInterface.OnClickListener() { .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
@@ -74,8 +74,7 @@ public class MainActivity extends Activity {
Bundle bundle = ai.metaData; Bundle bundle = ai.metaData;
supportedPackages = bundle.getString("android.accounts.SupportedAccountTypes"); supportedPackages = bundle.getString("android.accounts.SupportedAccountTypes");
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.e("PushApiTestAppOne", "Failed to load meta-data, NameNotFound: " Log.e("PushApiTestAppOne", "Failed to load meta-data, NameNotFound: " + e.getMessage());
+ e.getMessage());
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e("PushApiTestAppOne", "Failed to load meta-data, NullPointer: " + e.getMessage()); Log.e("PushApiTestAppOne", "Failed to load meta-data, NullPointer: " + e.getMessage());
} }
@@ -86,27 +85,48 @@ public class MainActivity extends Activity {
} }
if (masterString.length() > 0) { if (masterString.length() > 0) {
loginTypesRegistered.setText(masterString); loginTypesRegistered.setText(masterString);
} } else {
else {
loginTypesRegistered.setText("----"); loginTypesRegistered.setText("----");
} }
getVisibleAccounts.setOnClickListener(new View.OnClickListener() { getVisibleAccounts.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//int result = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS);
//if (result != PackageManager.PERMISSION_GRANTED) {
// ActivityCompat.requestPermissions(this,
// new String[]{Manifest.permission.GET_ACCOUNTS}, 101);
//}
Account[] accountsAccessedByAuthApp = am.getAccounts(); Account[] accountsAccessedByAuthApp = am.getAccounts();
StringBuilder masterString = new StringBuilder(); StringBuilder masterString = new StringBuilder();
for (int i = 0; i < accountsAccessedByAuthApp.length; i++) { for (int i = 0; i < accountsAccessedByAuthApp.length; i++) {
masterString.append(accountsAccessedByAuthApp[i].name + ", " + masterString.append(accountsAccessedByAuthApp[i].name + ", "
accountsAccessedByAuthApp[i].type + "\n"); + accountsAccessedByAuthApp[i].type + "\n");
} }
if (masterString.length() > 0) { if (masterString.length() > 0) {
visibleAccounts.setText(masterString); visibleAccounts.setText(masterString);
} } else {
else {
visibleAccounts.setText("----"); visibleAccounts.setText("----");
} }
Intent intent = AccountManager.newChooseAccountIntent(null, null, null, null, null,
null, null); // Show all accounts
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
} }
}); });
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
// Receiving a result from the AccountPicker
if (resultCode == RESULT_OK) {
Toast.makeText(this, data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE),
Toast.LENGTH_LONG).show();
// data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "No account was chosen", Toast.LENGTH_LONG).show();
}
}
}
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.example.android.pushapithirdpartytwo; package com.example.android.pushapithirdpartyone;
import android.accounts.Account; import android.accounts.Account;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -27,8 +27,9 @@ public class MessageReceiver extends BroadcastReceiver{
private static final String TAG = "PushApiTestAppOne"; private static final String TAG = "PushApiTestAppOne";
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Toast.makeText(context, " android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received", Toast.makeText(context,
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
Log.i(TAG, "android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
} }
} }

View File

@@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current
LOCAL_DEX_PREOPT := false LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert
include $(BUILD_PACKAGE) include $(BUILD_PACKAGE)
# Use the following include to make our test apk. # Use the following include to make our test apk.

View File

@@ -17,7 +17,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.pushapithirdpartytwo"> package="com.example.android.pushapithirdpartytwo">
<!-- <uses-permission android:name="android.permission.GET_ACCOUNTS"/> --> <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-sdk android:minSdkVersion="1"
android:targetSdkVersion="1001"
android:maxSdkVersion="11000" />
<application android:label="3P App 2" android:icon="@drawable/push"> <application android:label="3P App 2" android:icon="@drawable/push">
<activity android:name="MainActivity"> <activity android:name="MainActivity">
<intent-filter> <intent-filter>
@@ -27,7 +30,7 @@
</activity> </activity>
<receiver android:name="com.example.android.pushapithirdpartytwo.MessageReceiver"> <receiver android:name="com.example.android.pushapithirdpartytwo.MessageReceiver">
<intent-filter> <intent-filter>
<action android:name="android.accounts.VISIBLE_ACCOUNTS_CHANGED"/> <action android:name="android.accounts.action.VISIBLE_ACCOUNTS_CHANGED"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<meta-data <meta-data

Binary file not shown.

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID/TCCAuWgAwIBAgIJAKmfnlOvpOpWMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD
VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g
VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE
AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe
Fw0xNzAxMDUyMTE3MDZaFw00NDA1MjMyMTE3MDZaMIGUMQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEQMA4G
A1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UEAwwHQW5kcm9p
ZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAMPDrEJtdZZxeUuBJbEFojV7t6nD4fgcLpmd
hCbxp8BJsqTgcnMcqAT0h2IH+2QByjMaY7qaE0oDrr2555fznZdJwABU1Jx0ROtW
cT5GxhkRBoEGpY+zydMmNgl1hb9wAHl1bm3PF+XFq1oO9f3Oc2Igy0ahF1vyOAZv
kKGxb5ejGUX3nlb3rfKn6/1jro8WzEJf9fhXZIQQmeF7RPBFU9zYELX1U+7ntcX9
ZyXLaJxCJb06a7HQ6BG2twc9IOiIIrUbfIlDTNRnGOHqPT333QSkbsuNk7uRNnqj
SNICVhrZxjDf3O/pWh3L84+W+A3VaXT3QBA2OLUuVqsJZRbSiSMCAwEAAaNQME4w
HQYDVR0OBBYEFBdPzoirByhAhDXNyOwqdnDnAv4zMB8GA1UdIwQYMBaAFBdPzoir
ByhAhDXNyOwqdnDnAv4zMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
AH37TTRazxNg2WPBUF2wOKK97wXRtt91HiSKLx+jzKZW32k/0CTcDhtc/MX0xWBq
QZvv2K2HaOqwkWkhGHy0tixLQ+IMrEHCGMqfjZpmvOEAnsI+HTefxDcepT3JcdKX
mXsxUqNY3JgI0PCoWBwpeLMJiFDSxGM9owiCspUVONyDg6ZCeG8uZp7dGmDjIFqR
odApWDBu0iak0b4g+nzIs8Wy5QZRY+mQy14IOvoeAeLBofSHotswgZAhXwpl6xP9
y2kL0VV9pTlzNgGmmgxhNXW+6L+Ondcnsh8JNfCLuK4472Pazd8rvEkWPF0fTKeZ
zL8zfCYYur8uYjQQJhIoiYo=
-----END CERTIFICATE-----

View File

@@ -32,7 +32,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test Application Two" android:text="Test Application Two"
android:id="@+id/testapptext" android:id="@+id/testapponetext"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="27dp" /> android:layout_marginTop="27dp" />
@@ -44,7 +44,7 @@
android:text="Visible Accounts" android:text="Visible Accounts"
android:id="@+id/visibleaccountstext" android:id="@+id/visibleaccountstext"
android:layout_marginTop="58dp" android:layout_marginTop="58dp"
android:layout_below="@+id/testapptext" android:layout_below="@+id/testapponetext"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> android:layout_alignParentStart="true" />

View File

@@ -46,6 +46,7 @@ public class MainActivity extends Activity {
* Called with the activity is first created. * Called with the activity is first created.
*/ */
private static AccountManager am; private static AccountManager am;
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -55,15 +56,14 @@ public class MainActivity extends Activity {
final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered); final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered);
final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts); final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts);
final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts); final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts);
final Toast notifOn = Toast.makeText(getApplicationContext(), "Notifs Turned On!", final Toast notifOn =
Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Notifs Turned On!", Toast.LENGTH_SHORT);
final Toast notifOff = Toast.makeText(getApplicationContext(), "Notifs Turned Off!", final Toast notifOff =
Toast.LENGTH_SHORT); Toast.makeText(getApplicationContext(), "Notifs Turned Off!", Toast.LENGTH_SHORT);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Welcome to Test App 1.\nPlease make sure you have:\n\n1. Test App 1\n" builder.setMessage("Welcome to Test App 2.\nPlease make sure you have:\n\n1. Test App 2\n"
+ "\n2. Auth App \n\ninstalled for the demo. These applications together provide" + + "\n2. Auth App \n\ninstalled for the demo. These applications together provide"
" tests, use cases, and proof of concept of Push API!\n") + " tests, use cases, and proof of concept of Push API!\n").setTitle("WELCOME")
.setTitle("WELCOME")
.setPositiveButton("Okay", new DialogInterface.OnClickListener() { .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
@@ -79,8 +79,7 @@ public class MainActivity extends Activity {
Bundle bundle = ai.metaData; Bundle bundle = ai.metaData;
supportedPackages = bundle.getString("android.accounts.SupportedAccountTypes"); supportedPackages = bundle.getString("android.accounts.SupportedAccountTypes");
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.e("PushApiTestAppTwo", "Failed to load meta-data, NameNotFound: " Log.e("PushApiTestAppTwo", "Failed to load meta-data, NameNotFound: " + e.getMessage());
+ e.getMessage());
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e("PushApiTestAppTwo", "Failed to load meta-data, NullPointer: " + e.getMessage()); Log.e("PushApiTestAppTwo", "Failed to load meta-data, NullPointer: " + e.getMessage());
} }
@@ -91,8 +90,7 @@ public class MainActivity extends Activity {
} }
if (masterString.length() > 0) { if (masterString.length() > 0) {
loginTypesRegistered.setText(masterString); loginTypesRegistered.setText(masterString);
} } else {
else {
loginTypesRegistered.setText("----"); loginTypesRegistered.setText("----");
} }
getVisibleAccounts.setOnClickListener(new View.OnClickListener() { getVisibleAccounts.setOnClickListener(new View.OnClickListener() {
@@ -101,15 +99,18 @@ public class MainActivity extends Activity {
Account[] accountsAccessedByAuthApp = am.getAccounts(); Account[] accountsAccessedByAuthApp = am.getAccounts();
StringBuilder masterString = new StringBuilder(); StringBuilder masterString = new StringBuilder();
for (int i = 0; i < accountsAccessedByAuthApp.length; i++) { for (int i = 0; i < accountsAccessedByAuthApp.length; i++) {
masterString.append(accountsAccessedByAuthApp[i].name + ", " + masterString.append(accountsAccessedByAuthApp[i].name + ", "
accountsAccessedByAuthApp[i].type + "\n"); + accountsAccessedByAuthApp[i].type + "\n");
} }
if (masterString.length() > 0) { if (masterString.length() > 0) {
visibleAccounts.setText(masterString); visibleAccounts.setText(masterString);
} } else {
else {
visibleAccounts.setText("----"); visibleAccounts.setText("----");
} }
Intent intent = AccountManager.newChooseAccountIntent(null, null, null, null, null,
null, null); // Show all accounts
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
} }
}); });
} }

View File

@@ -27,8 +27,9 @@ public class MessageReceiver extends BroadcastReceiver{
private static final String TAG = "PushApiTestAppTwo"; private static final String TAG = "PushApiTestAppTwo";
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Toast.makeText(context, " android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received", Toast.makeText(context,
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
Log.i(TAG, "android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
} }
} }