From b99e8db305170b7bad6ee293c337831bb754db06 Mon Sep 17 00:00:00 2001 From: Dmitry Dementyev Date: Thu, 22 Dec 2016 12:50:37 -0800 Subject: [PATCH] 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 --- apps/PushApiAuthenticator/Android.mk | 2 + apps/PushApiAuthenticator/AndroidManifest.xml | 8 +- apps/PushApiAuthenticator/cert.pk8 | Bin 0 -> 1216 bytes apps/PushApiAuthenticator/cert.x509.pem | 24 +++ .../res/layout/activity_main.xml | 24 ++- .../pushapiauthenticator/MainActivity.java | 167 ++++++++++-------- .../pushapiauthenticator/MessageReceiver.java | 37 ++++ apps/PushApiTestAppOne/Android.mk | 2 + apps/PushApiTestAppOne/AndroidManifest.xml | 7 +- apps/PushApiTestAppOne/cert.pk8 | Bin 0 -> 1218 bytes apps/PushApiTestAppOne/cert.x509.pem | 24 +++ .../pushapithirdpartyone/MainActivity.java | 66 ++++--- .../pushapithirdpartyone/MessageReceiver.java | 9 +- apps/PushApiTestAppTwo/Android.mk | 2 + apps/PushApiTestAppTwo/AndroidManifest.xml | 7 +- apps/PushApiTestAppTwo/cert.pk8 | Bin 0 -> 1217 bytes apps/PushApiTestAppTwo/cert.x509.pem | 24 +++ .../res/layout/activity_main.xml | 6 +- .../pushapithirdpartytwo/MainActivity.java | 49 ++--- .../pushapithirdpartytwo/MessageReceiver.java | 7 +- 20 files changed, 327 insertions(+), 138 deletions(-) create mode 100644 apps/PushApiAuthenticator/cert.pk8 create mode 100644 apps/PushApiAuthenticator/cert.x509.pem create mode 100644 apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MessageReceiver.java create mode 100644 apps/PushApiTestAppOne/cert.pk8 create mode 100644 apps/PushApiTestAppOne/cert.x509.pem create mode 100644 apps/PushApiTestAppTwo/cert.pk8 create mode 100644 apps/PushApiTestAppTwo/cert.x509.pem diff --git a/apps/PushApiAuthenticator/Android.mk b/apps/PushApiAuthenticator/Android.mk index 8616882b6..58e2e51c0 100644 --- a/apps/PushApiAuthenticator/Android.mk +++ b/apps/PushApiAuthenticator/Android.mk @@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current LOCAL_DEX_PREOPT := false +LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert + include $(BUILD_PACKAGE) # Use the following include to make our test apk. diff --git a/apps/PushApiAuthenticator/AndroidManifest.xml b/apps/PushApiAuthenticator/AndroidManifest.xml index 7628a6b68..dd602c76f 100644 --- a/apps/PushApiAuthenticator/AndroidManifest.xml +++ b/apps/PushApiAuthenticator/AndroidManifest.xml @@ -26,6 +26,12 @@ + + + + + + @@ -38,4 +44,4 @@ android:resource="@xml/authenticator" /> - \ No newline at end of file + diff --git a/apps/PushApiAuthenticator/cert.pk8 b/apps/PushApiAuthenticator/cert.pk8 new file mode 100644 index 0000000000000000000000000000000000000000..8b894b429c2921e858a1b8700d4bebdd3b4e8059 GIT binary patch literal 1216 zcmV;x1V8&Qf&{z*0RS)!1_>&LNQUrrZ9p8q5=T`0)hbn0J~Fe%=}K| zuaqIsTakKs3cujsZEv))W{G3`f8d#iU2DWE(20k0IDS?7>ig+U4j3iP_?kn^cy9{i z5{Zv`riKYiLuioA*~R5*H#`;w@c)^TM>nL$(qf&%Fi>$$k`DtDxKlYYYDaOx1YQ>a zg^$MdtaNn=;?9CNNWN-B5}jfr-I%SW*ZMvxeUly0m+iOUvPj4*SYjsw1{`^HR>U_o z2}r(3nOxt1Y~k^mqMO~%n#DbDz+o~kIj$J^9uV&*f3-FDVfWCy!)_QxhQoU7vfjmU z#q61+P0M?Fqz>(LAX%Ldr@HY8lhKF2LXImui%KF9HJr009Dm0RVg* zHHLqUP8+`r0AC9(m{2tRtMwLCB=@HTCSn`U-A-D5seudrK&vO2lpJX|6r;!h6iz7j z&fDb1)PgI%a>p)vt?)&$+mZBoqB~-SJ*Okm{)SB{(sN{gp1HmPVK(YerRA8M}-N z5d5oTqUmIYXCW%!rQRgA=I5+pp{O%-G#g8I(Cr^7Z(?k{u92SPPib8QVxaE$<2TCC9YUyODX>@Z0_lN+8!mB5OYCh+ej@ixm1?himQ% z{O(&CYs0*Sg2d0eTBYkDb;eEZ-!pc)?f+3(hH_n{aPB;0W>hI%OnC(x?uBFr+ydR8 z5-L>IXAWJ>4p6IH3W^|VdhZ6C=J(#ON!8Iqk;CBLn zfD5pPru!98G$Xmy)t^~JQZdX8Lv6Z~=1^sA|IO^&CC2Bzhr}=Rr)2@;WTHo87t>U4 zTD&1!B~q*T6sTG$p%hS&z-t)$0@SL+A#XIK@@a| z%Ox0&7sEMi&2D41-1<&~W=(3x*kZ5@*dToeh#2#!DtpRU4Jgwskf_!yw7v(@?tc9Q z(H3SPQp@5uF|zneBrVrg^{nm0i=mXJAqx4Zi%;{e9^5ES!)oXoHgxM;l`smev@0A} z0)c=i6d7)om82ug7+Eu6*9*hd}e5FJJH-z$IdB9e} zAo#j5T^W)<{(4gV0Li`caWz1@^=zknM5j*Y^daR`pG5e2TS2CaC@|Xw`^j}3JH@5( e;aj&+fMN;S+bf7IPok;T{(|6wbOYantR)u@8%mG> literal 0 HcmV?d00001 diff --git a/apps/PushApiAuthenticator/cert.x509.pem b/apps/PushApiAuthenticator/cert.x509.pem new file mode 100644 index 000000000..6f2370f05 --- /dev/null +++ b/apps/PushApiAuthenticator/cert.x509.pem @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIID/TCCAuWgAwIBAgIJAKRuYMXiytGmMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD +VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g +VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE +AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe +Fw0x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eCgE8ea+0Jz+9KD3wHPmX9aUryFQQaC +NJ70c2gKCJ8hi0pPlWQZ5Ec= +-----END CERTIFICATE----- diff --git a/apps/PushApiAuthenticator/res/layout/activity_main.xml b/apps/PushApiAuthenticator/res/layout/activity_main.xml index 52c17ea72..d4616f938 100644 --- a/apps/PushApiAuthenticator/res/layout/activity_main.xml +++ b/apps/PushApiAuthenticator/res/layout/activity_main.xml @@ -146,7 +146,7 @@ @@ -154,15 +154,22 @@ + + + + 0) { getAllRequesting3pUids.setText(uidMasterString); @@ -123,8 +123,8 @@ public class MainActivity extends Activity { getAllRequesting3pPackages.setText("----"); } } else { - getAllRequesting3pPackages.setText("----"); - getAllRequesting3pUids.setText("----"); + getAllRequesting3pPackages.setText("----"); + getAllRequesting3pUids.setText("----"); } } }); @@ -132,9 +132,7 @@ public class MainActivity extends Activity { selectOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - //TODO update Authenticator once AccountManager API is updated - /* - Account currentAccount = terraAccount; + /*Account currentAccount = terraAccount; int checkedAccount = accountChooser.getCheckedRadioButtonId(); int checkedOption = optionChooser.getCheckedRadioButtonId(); if (uidChooser.getText().length() == 0) { @@ -144,7 +142,7 @@ public class MainActivity extends Activity { } else if (checkedOption == -1) { chooseOptionWarning.show(); } else { - //all conditions satisfied + // all conditions satisfied if (checkedAccount == R.id.terrabutton) { currentAccount = terraAccount; } else if (checkedAccount == R.id.aquabutton) { @@ -154,53 +152,83 @@ public class MainActivity extends Activity { } String uidstr = uidChooser.getText().toString(); int uid = Integer.parseInt(uidstr); - if (checkedOption == R.id.addButton) { - am.makeAccountVisible(currentAccount, uid); - Toast.makeText(getApplicationContext(), "Giving Visibility of " + - currentAccount.name + " to " + - getPackageManager().getNameForUid(uid), + if (checkedOption == R.id.visibleButton) { + am.setAccountVisibility(currentAccount, uid, + AccountManager.VISIBILITY_USER_MANAGED_VISIBLE); + Toast.makeText(getApplicationContext(), + "Giving visibility of " + currentAccount.name + " to " + + getPackageManager().getNameForUid(uid), Toast.LENGTH_SHORT).show(); - } else if (checkedOption == R.id.removeButton) { - am.removeAccountVisibility(currentAccount, uid); - Toast.makeText(getApplicationContext(), "Removing Visibility of " + - currentAccount.name + " to " + - getPackageManager().getNameForUid(uid), + } else if (checkedOption == R.id.notVisibleButton) { + am.setAccountVisibility(currentAccount, uid, + AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE); + Toast.makeText(getApplicationContext(), + "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(); - } else if (checkedOption == R.id.getButton) { - Toast.makeText(getApplicationContext(), "Is " + currentAccount.name + - " visible to " + getPackageManager().getNameForUid(uid) + "?\n" + - am.isAccountVisible(currentAccount, uid), Toast.LENGTH_SHORT) - .show(); + Toast.makeText(getApplicationContext(), + "Is " + currentAccount.name + " visible to " + + getPackageManager().getNameForUid(uid) + "?\n" + + am.getAccountVisibility(currentAccount, uid), + Toast.LENGTH_SHORT).show(); } else if (checkedOption == R.id.addAccountButton) { - Toast.makeText(getApplicationContext(), "Adding account explicitly!" - + am.addAccountExplicitly(currentAccount, null, null), + Toast.makeText(getApplicationContext(), + "Adding account explicitly!" + + am.addAccountExplicitly(currentAccount, null, null), Toast.LENGTH_SHORT).show(); } else if (checkedOption == R.id.addAccountButtonWithUid) { - int[] uidsToAdd = new int[] {uid}; - Toast.makeText(getApplicationContext(), "Adding account explicitly!" - + am.addAccountExplicitly(currentAccount, null, null, uidsToAdd) - + " TO: " + getPackageManager().getNameForUid(uid) + "!", + HashMap uidsAndVisibility = new HashMap<>(); + uidsAndVisibility.put(uid, AccountManager.VISIBILITY_USER_MANAGED_VISIBLE); + Toast.makeText(getApplicationContext(), + "Adding account explicitly!" + + am.addAccountExplicitly(currentAccount, null, null, + uidsAndVisibility) + + " TO: " + getPackageManager().getNameForUid(uid) + "!", Toast.LENGTH_SHORT).show(); } else if (checkedOption == R.id.removeAccount) { - Toast.makeText(getApplicationContext(), "Removing account explicitly!" - + am.removeAccountExplicitly(currentAccount), + Toast.makeText(getApplicationContext(), + "Removing account explicitly!" + + am.removeAccountExplicitly(currentAccount), Toast.LENGTH_SHORT).show(); + } else if (checkedOption == R.id.renameAccount) { + try { + AccountManagerFuture 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(); String uidMasterString = getAllRequesting3pUids.getText().toString(); - int[] allUids = am.getRequestingUidsForType(getApplicationContext(). - getPackageName()); + int[] allUids = null; + //am.getRequestingUidsForType(getApplicationContext().getPackageName()); if (allUids != null) { - for (int i = 0 ; i < allUids.length ; i++) { + for (int i = 0; i < allUids.length; i++) { 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 + ","); } - if (am.isAccountVisible(aquaAccount, allUids[i])) { + if (am.getAccountVisibility(aquaAccount, + allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) { 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("\n"); @@ -208,13 +236,10 @@ public class MainActivity extends Activity { } if (masterString.length() > 0) { authStatus.setText(masterString); - } - else { + } else { authStatus.setText("----"); } - } - */ + }*/ } }); - } -} +}} diff --git a/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MessageReceiver.java b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MessageReceiver.java new file mode 100644 index 000000000..476fdcbb5 --- /dev/null +++ b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MessageReceiver.java @@ -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(); + } + + } +} diff --git a/apps/PushApiTestAppOne/Android.mk b/apps/PushApiTestAppOne/Android.mk index ccd2236d6..35d596c12 100644 --- a/apps/PushApiTestAppOne/Android.mk +++ b/apps/PushApiTestAppOne/Android.mk @@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current LOCAL_DEX_PREOPT := false +LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert + include $(BUILD_PACKAGE) # Use the following include to make our test apk. diff --git a/apps/PushApiTestAppOne/AndroidManifest.xml b/apps/PushApiTestAppOne/AndroidManifest.xml index 54be509d3..01a2fd73d 100644 --- a/apps/PushApiTestAppOne/AndroidManifest.xml +++ b/apps/PushApiTestAppOne/AndroidManifest.xml @@ -18,6 +18,9 @@ + @@ -27,11 +30,11 @@ - + + android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator"/> diff --git a/apps/PushApiTestAppOne/cert.pk8 b/apps/PushApiTestAppOne/cert.pk8 new file mode 100644 index 0000000000000000000000000000000000000000..052c03efac8a65e3795a5d022e8fbf29375b2725 GIT binary patch literal 1218 zcmV;z1U>sOf&{(-0RS)!1_>&LNQUrs4#*Aqyhl|0)hbn0MVl4yy=Bw zUj20m;~LpQVG`l!J??hx*`t5x3Gmb}`+V6LgvO6tIitJvcn+(AL@*_a6iKpL-nz=a z+?rY975^7pT#ONRu=iSoWFO$PiA9mSn-HUVL`U^*uTaYXEe)KK9DhLLR%jL}GK$eBO>IY{72(Ft)a7=9lf7or065^2a zu8i;MOkAd*Vz%w7*z;dzNea^imckul2lz_nv5#CAZ1?_>f`emk9XUr*r4BE zwpfV}C?Dg*-wsC^pKa;54h)&k_}NzEW!Y(gh%JHi?a~~i%r-+Ih`5iz`ocKdh`fq?+= zFg2==eh~sXta;S<-br%=d5CT}>IDT@-%xD^rU#;|tG|STKz(PX$rM@UIBmZO#5988nf)XPC(X zfq-6&GL3;Czf>z?4}@@L+fFW1;wq~?`R3)e?G->o_q$4qEm5hd)PcK!cvspqE`>L8 zd%vfW^|IU++#!d-hM3kfPgYuczveV_GwC8-YrRHk^pEizX&vcqfBGX^d23IJgbBsm zJw+;!>+x1L(a+>x0kATtbBu$!vsEKy_{{==fdGl5?bCBdo)!fJL)JDTVGUt-Y%#m2 z-0fd_h(>4gzVNg#V}7^S%wUf%Qw&Vjoq6~5B3sl1ISS;oxizdM+Lf<6u=T?LpCjG3 zNh_;2!6VYiFqj?8T@Y?AfI*@w!En)N{N|pGp_Zm%*|yZg4|nm@VxI&~R=8N=Qn$B6 z@TmfUfG0i_e4?QWQ54eyi|QIAHZ^WixJu&9K5(gmpo!(Q(c|aF7gHU&^N2ZR-we#v zLt1*FUX8ReDNKF`G`_k=;Xwmckon%~1$ylW!&E!e4-*zpu&ZxS 0) { loginTypesRegistered.setText(masterString); - } - else { + } else { loginTypesRegistered.setText("----"); } getVisibleAccounts.setOnClickListener(new View.OnClickListener() { @Override 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(); StringBuilder masterString = new StringBuilder(); - for (int i = 0 ; i < accountsAccessedByAuthApp.length ; i++) { - masterString.append(accountsAccessedByAuthApp[i].name + ", " + - accountsAccessedByAuthApp[i].type + "\n"); + for (int i = 0; i < accountsAccessedByAuthApp.length; i++) { + masterString.append(accountsAccessedByAuthApp[i].name + ", " + + accountsAccessedByAuthApp[i].type + "\n"); } if (masterString.length() > 0) { visibleAccounts.setText(masterString); - } - else { + } else { 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(); + } + } + } } diff --git a/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java index 754c3d84b..9fce46d03 100644 --- a/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java +++ b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.android.pushapithirdpartytwo; +package com.example.android.pushapithirdpartyone; import android.accounts.Account; import android.content.BroadcastReceiver; @@ -23,12 +23,13 @@ import android.content.Intent; import android.util.Log; import android.widget.Toast; -public class MessageReceiver extends BroadcastReceiver{ +public class MessageReceiver extends BroadcastReceiver { private static final String TAG = "PushApiTestAppOne"; 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(); - Log.i(TAG, "android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); + Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); } } diff --git a/apps/PushApiTestAppTwo/Android.mk b/apps/PushApiTestAppTwo/Android.mk index a46f3f0a9..fe76b2c16 100644 --- a/apps/PushApiTestAppTwo/Android.mk +++ b/apps/PushApiTestAppTwo/Android.mk @@ -12,6 +12,8 @@ LOCAL_SDK_VERSION := current LOCAL_DEX_PREOPT := false +LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert + include $(BUILD_PACKAGE) # Use the following include to make our test apk. diff --git a/apps/PushApiTestAppTwo/AndroidManifest.xml b/apps/PushApiTestAppTwo/AndroidManifest.xml index 8ff970da4..5d17acac9 100644 --- a/apps/PushApiTestAppTwo/AndroidManifest.xml +++ b/apps/PushApiTestAppTwo/AndroidManifest.xml @@ -17,7 +17,10 @@ - + + @@ -27,7 +30,7 @@ - + &LNQUrr!ay9qXGc{0)hbn0K>zqLTz=H zad}IDC9wsfHG8+I!{PWGE}5N#Ch@1hNwTEia&sK01oVeu2m53J$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)~|FA!bi1#nME*2R*YgDTie6 z^9D6%8mnKR$Z)*eP|-XV;u^FzFzV`{&`F&ZdOc!}Fx-=U;FJ(At#CtJuIY9#C>~#^ fFYynH4wPcBz2x)(3gZc?P#0!}%%%JtDPkY{pn^q; literal 0 HcmV?d00001 diff --git a/apps/PushApiTestAppTwo/cert.x509.pem b/apps/PushApiTestAppTwo/cert.x509.pem new file mode 100644 index 000000000..2392a9e92 --- /dev/null +++ b/apps/PushApiTestAppTwo/cert.x509.pem @@ -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----- diff --git a/apps/PushApiTestAppTwo/res/layout/activity_main.xml b/apps/PushApiTestAppTwo/res/layout/activity_main.xml index fe91a9015..244765b72 100644 --- a/apps/PushApiTestAppTwo/res/layout/activity_main.xml +++ b/apps/PushApiTestAppTwo/res/layout/activity_main.xml @@ -32,7 +32,7 @@ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Test Application Two" - android:id="@+id/testapptext" + android:id="@+id/testapponetext" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="27dp" /> @@ -44,7 +44,7 @@ android:text="Visible Accounts" android:id="@+id/visibleaccountstext" android:layout_marginTop="58dp" - android:layout_below="@+id/testapptext" + android:layout_below="@+id/testapponetext" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> @@ -89,4 +89,4 @@ - + \ No newline at end of file diff --git a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java index 0eaf98344..1bde4a52c 100644 --- a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java +++ b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java @@ -46,6 +46,7 @@ public class MainActivity extends Activity { * Called with the activity is first created. */ private static AccountManager am; + private static final int REQUEST_CODE_PICK_ACCOUNT = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -55,44 +56,41 @@ public class MainActivity extends Activity { final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered); final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts); final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts); - final Toast notifOn = Toast.makeText(getApplicationContext(), "Notifs Turned On!", - Toast.LENGTH_SHORT); - final Toast notifOff = Toast.makeText(getApplicationContext(), "Notifs Turned Off!", - Toast.LENGTH_SHORT); + final Toast notifOn = + Toast.makeText(getApplicationContext(), "Notifs Turned On!", Toast.LENGTH_SHORT); + final Toast notifOff = + Toast.makeText(getApplicationContext(), "Notifs Turned Off!", Toast.LENGTH_SHORT); 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" - + "\n2. Auth App \n\ninstalled for the demo. These applications together provide" + - " tests, use cases, and proof of concept of Push API!\n") - .setTitle("WELCOME") + 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" + + " tests, use cases, and proof of concept of Push API!\n").setTitle("WELCOME") .setPositiveButton("Okay", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - //do nothing - } - }); + @Override + public void onClick(DialogInterface dialogInterface, int i) { + // do nothing + } + }); AlertDialog dialog = builder.create(); dialog.show(); String supportedPackages = ""; - try{ + try { ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; supportedPackages = bundle.getString("android.accounts.SupportedAccountTypes"); } catch (PackageManager.NameNotFoundException e) { - Log.e("PushApiTestAppTwo", "Failed to load meta-data, NameNotFound: " - + e.getMessage()); + Log.e("PushApiTestAppTwo", "Failed to load meta-data, NameNotFound: " + e.getMessage()); } catch (NullPointerException e) { Log.e("PushApiTestAppTwo", "Failed to load meta-data, NullPointer: " + e.getMessage()); } String[] manifestSupportedAccountTypes = supportedPackages.split(";"); final StringBuilder masterString = new StringBuilder(); - for (int i = 0 ; i < manifestSupportedAccountTypes.length ; i++) { + for (int i = 0; i < manifestSupportedAccountTypes.length; i++) { masterString.append(manifestSupportedAccountTypes[i] + "\n"); } if (masterString.length() > 0) { loginTypesRegistered.setText(masterString); - } - else { + } else { loginTypesRegistered.setText("----"); } getVisibleAccounts.setOnClickListener(new View.OnClickListener() { @@ -100,16 +98,19 @@ public class MainActivity extends Activity { public void onClick(View view) { Account[] accountsAccessedByAuthApp = am.getAccounts(); StringBuilder masterString = new StringBuilder(); - for (int i = 0 ; i < accountsAccessedByAuthApp.length ; i++) { - masterString.append(accountsAccessedByAuthApp[i].name + ", " + - accountsAccessedByAuthApp[i].type + "\n"); + for (int i = 0; i < accountsAccessedByAuthApp.length; i++) { + masterString.append(accountsAccessedByAuthApp[i].name + ", " + + accountsAccessedByAuthApp[i].type + "\n"); } if (masterString.length() > 0) { visibleAccounts.setText(masterString); - } - else { + } else { visibleAccounts.setText("----"); } + + Intent intent = AccountManager.newChooseAccountIntent(null, null, null, null, null, + null, null); // Show all accounts + startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT); } }); } diff --git a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java index 0325d80cd..55ef02d53 100644 --- a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java +++ b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java @@ -23,12 +23,13 @@ import android.content.Intent; import android.util.Log; import android.widget.Toast; -public class MessageReceiver extends BroadcastReceiver{ +public class MessageReceiver extends BroadcastReceiver { private static final String TAG = "PushApiTestAppTwo"; 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(); - Log.i(TAG, "android.accounts.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); + Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received"); } }