Update account visibility test apps.
Test: manual tests Bug: 34841115 Change-Id: I431db9bb2c133789028b3e2bcde2cf445d1e76a1
This commit is contained in:
@@ -46,44 +46,23 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="UIDs"
|
||||
android:text="pushapi packages: "
|
||||
android:id="@+id/textView8"
|
||||
android:layout_below="@+id/textView7"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="Packages"
|
||||
android:id="@+id/textView9"
|
||||
android:layout_below="@+id/uidsrequestingapps"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginTop="63dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="-----"
|
||||
android:id="@+id/uidsrequestingapps"
|
||||
android:id="@+id/requestingapps"
|
||||
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/textView8"
|
||||
android:layout_toRightOf="@+id/authenticatorstatus" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="-----"
|
||||
android:id="@+id/packagesrequestingapps"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/textView9"
|
||||
android:layout_alignRight="@+id/textView11" />
|
||||
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -91,8 +70,8 @@
|
||||
android:text="GET!"
|
||||
android:id="@+id/getallrequestingapps"
|
||||
android:layout_alignTop="@+id/textView7"
|
||||
android:layout_toRightOf="@+id/textView3"
|
||||
android:layout_toEndOf="@+id/textView3" />
|
||||
android:layout_toRightOf="@+id/textView7"
|
||||
android:layout_toEndOf="@+id/textView7" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -101,7 +80,7 @@
|
||||
android:text="Choose Account"
|
||||
android:id="@+id/textView10"
|
||||
android:layout_marginTop="57dp"
|
||||
android:layout_below="@+id/packagesrequestingapps"
|
||||
android:layout_below="@+id/requestingapps"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
@@ -135,13 +114,44 @@
|
||||
android:checked="false" />
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Packages"
|
||||
android:id="@+id/textViewPackages"
|
||||
android:layout_below="@+id/accountGroup"
|
||||
android:layout_alignParentLeft="true" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:id="@+id/packagesChooser"
|
||||
android:layout_below="@+id/textViewPackages"
|
||||
android:layout_alignParentLeft="true">
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="com.example.android.pushapithirdpartyone"
|
||||
android:id="@+id/apponebutton"
|
||||
android:checked="false" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="com.example.android.pushapithirdpartytwo"
|
||||
android:id="@+id/apptwobutton"
|
||||
android:checked="false" />
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Options"
|
||||
android:id="@+id/textView11"
|
||||
android:layout_below="@+id/accountGroup"
|
||||
android:layout_below="@+id/packagesChooser"
|
||||
android:layout_alignParentLeft="true" />
|
||||
|
||||
<RadioGroup
|
||||
@@ -154,21 +164,21 @@
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SET VISIBLE (MANAGED)"
|
||||
android:text="SET UM_VISIBLE (2)"
|
||||
android:id="@+id/visibleButton"
|
||||
android:checked="false" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SET NOT_VISIBLE (MANAGED)"
|
||||
android:text="SET UM_NOT_VISIBLE(4)"
|
||||
android:id="@+id/notVisibleButton"
|
||||
android:checked="false" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SET NOT_VISIBLE"
|
||||
android:text="SET NOT_VISIBLE(3)"
|
||||
android:id="@+id/forcedNotVisibleButton"
|
||||
android:checked="false" />
|
||||
|
||||
@@ -189,8 +199,8 @@
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ADD ACCOUNT EXPLICITLY w/ UID"
|
||||
android:id="@+id/addAccountButtonWithUid"
|
||||
android:text="ADD ACCOUNT (With visibility)"
|
||||
android:id="@+id/addAccountButtonWithVisibility"
|
||||
android:checked="false" />
|
||||
|
||||
<RadioButton
|
||||
@@ -237,24 +247,6 @@
|
||||
android:layout_below="@+id/textView12"
|
||||
android:layout_alignParentLeft="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Authenticator Application"
|
||||
android:id="@+id/textView3"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/uidchooser"
|
||||
android:layout_below="@+id/optionsGroup"
|
||||
android:layout_alignRight="@+id/getallrequestingapps"
|
||||
android:layout_alignEnd="@+id/getallrequestingapps"
|
||||
android:layout_marginTop="28dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.
|
||||
* 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;
|
||||
@@ -24,6 +27,8 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
@@ -35,6 +40,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
@@ -57,20 +63,18 @@ public class MainActivity extends Activity {
|
||||
|
||||
am = AccountManager.get(getApplicationContext());
|
||||
final Button getAllRequestingApps = (Button) findViewById(R.id.getallrequestingapps);
|
||||
final TextView getAllRequesting3pUids = (TextView) findViewById(R.id.uidsrequestingapps);
|
||||
final TextView getAllRequesting3pPackages =
|
||||
(TextView) findViewById(R.id.packagesrequestingapps);
|
||||
final TextView getAllRequesting3pUids = (TextView) findViewById(R.id.requestingapps);
|
||||
|
||||
final RadioGroup accountChooser = (RadioGroup) findViewById(R.id.accountGroup);
|
||||
final RadioGroup optionChooser = (RadioGroup) findViewById(R.id.optionsGroup);
|
||||
final EditText uidChooser = (EditText) findViewById(R.id.uidchooser);
|
||||
final RadioGroup packagesChooser = (RadioGroup) findViewById(R.id.packagesChooser);
|
||||
final Button selectOption = (Button) findViewById(R.id.selectoptionbutton);
|
||||
final TextView authStatus = (TextView) findViewById(R.id.authenticatorstatus);
|
||||
|
||||
final Toast hitGet =
|
||||
Toast.makeText(getApplicationContext(), "Hit the GET Button!", Toast.LENGTH_SHORT);
|
||||
final Toast enterUidWarning =
|
||||
Toast.makeText(getApplicationContext(), "Enter a UID!", Toast.LENGTH_SHORT);
|
||||
final Toast enterPackageName = Toast.makeText(getApplicationContext(),
|
||||
"Choose a packageName!", Toast.LENGTH_SHORT);
|
||||
final Toast chooseAccountWarning =
|
||||
Toast.makeText(getApplicationContext(), "Choose an Account!", Toast.LENGTH_SHORT);
|
||||
final Toast chooseOptionWarning =
|
||||
@@ -86,7 +90,7 @@ public class MainActivity extends Activity {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
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"
|
||||
+ " together provide tests, use cases, and proof of concept of Push API!\n")
|
||||
+ " provide tests, use cases, and proof of concept of Account Discovery API!\n")
|
||||
.setTitle("WELCOME")
|
||||
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -101,42 +105,33 @@ public class MainActivity extends Activity {
|
||||
getAllRequestingApps.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int[] allRequestedUids = null;
|
||||
// TODO remove uid part
|
||||
// am.getRequestingUidsForType(getApplicationContext().getPackageName());
|
||||
if (allRequestedUids != null) {
|
||||
List<ApplicationInfo> list = getPackageManager().getInstalledApplications(
|
||||
PackageManager.GET_META_DATA);
|
||||
StringBuilder uidMasterString = new StringBuilder();
|
||||
StringBuilder packageMasterString = new StringBuilder();
|
||||
for (int i = 0; i < allRequestedUids.length; i++) {
|
||||
uidMasterString.append(allRequestedUids[i] + ",\n\n");
|
||||
packageMasterString.append(
|
||||
getPackageManager().getNameForUid(allRequestedUids[i]) + ",\n\n");
|
||||
for (ApplicationInfo ai :list) {
|
||||
String label = (String) ai.processName;
|
||||
if (label.contains("pushapi")) {
|
||||
uidMasterString.append(label + "\n");
|
||||
}
|
||||
}
|
||||
if (uidMasterString.length() > 0) {
|
||||
getAllRequesting3pUids.setText(uidMasterString);
|
||||
} else {
|
||||
getAllRequesting3pUids.setText("----");
|
||||
}
|
||||
if (packageMasterString.length() > 0) {
|
||||
getAllRequesting3pPackages.setText(packageMasterString);
|
||||
} else {
|
||||
getAllRequesting3pPackages.setText("----");
|
||||
}
|
||||
} else {
|
||||
getAllRequesting3pPackages.setText("----");
|
||||
getAllRequesting3pUids.setText("----");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
selectOption.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
/*Account currentAccount = terraAccount;
|
||||
Account currentAccount = terraAccount;
|
||||
int checkedAccount = accountChooser.getCheckedRadioButtonId();
|
||||
int checkedOption = optionChooser.getCheckedRadioButtonId();
|
||||
if (uidChooser.getText().length() == 0) {
|
||||
enterUidWarning.show();
|
||||
int checkedApp = packagesChooser.getCheckedRadioButtonId();
|
||||
if (checkedApp == -1) {
|
||||
enterPackageName.show();
|
||||
} else if (checkedAccount == -1) {
|
||||
chooseAccountWarning.show();
|
||||
} else if (checkedOption == -1) {
|
||||
@@ -150,96 +145,80 @@ public class MainActivity extends Activity {
|
||||
} else if (checkedAccount == R.id.ventusbutton) {
|
||||
currentAccount = ventusAccount;
|
||||
}
|
||||
String uidstr = uidChooser.getText().toString();
|
||||
int uid = Integer.parseInt(uidstr);
|
||||
if (checkedOption == R.id.visibleButton) {
|
||||
am.setAccountVisibility(currentAccount, uid,
|
||||
String packageName =
|
||||
((RadioButton) findViewById(checkedApp)).getText().toString();
|
||||
switch (checkedOption) {
|
||||
case R.id.visibleButton:
|
||||
am.setAccountVisibility(currentAccount, packageName,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Giving visibility of " + currentAccount.name + " to "
|
||||
+ getPackageManager().getNameForUid(uid),
|
||||
Toast.makeText(
|
||||
getApplicationContext(), "Set UM_VISIBLE(2) "
|
||||
+ currentAccount.name + " to " + packageName,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.notVisibleButton) {
|
||||
am.setAccountVisibility(currentAccount, uid,
|
||||
break;
|
||||
case R.id.notVisibleButton:
|
||||
am.setAccountVisibility(currentAccount, packageName,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Removing visibility of " + currentAccount.name + " to "
|
||||
+ getPackageManager().getNameForUid(uid),
|
||||
Toast.makeText(
|
||||
getApplicationContext(), "Set UM_NOT_VISIBLE(4) "
|
||||
+ currentAccount.name + " to " + packageName,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.forcedNotVisibleButton) {
|
||||
am.setAccountVisibility(currentAccount, uid,
|
||||
break;
|
||||
case R.id.forcedNotVisibleButton:
|
||||
am.setAccountVisibility(currentAccount, packageName,
|
||||
AccountManager.VISIBILITY_NOT_VISIBLE);
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Removing visibility (not managed) of " + currentAccount.name
|
||||
+ " to " + getPackageManager().getNameForUid(uid),
|
||||
Toast.makeText(
|
||||
getApplicationContext(), "Removing visibility(3) "
|
||||
+ currentAccount.name + " of " + packageName,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.getButton) {
|
||||
break;
|
||||
case R.id.getButton:
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Is " + currentAccount.name + " visible to "
|
||||
+ getPackageManager().getNameForUid(uid) + "?\n"
|
||||
+ am.getAccountVisibility(currentAccount, uid),
|
||||
"Is " + currentAccount.name + " visible to " + packageName
|
||||
+ "?\n"
|
||||
+ am.getAccountVisibility(currentAccount, packageName),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.addAccountButton) {
|
||||
break;
|
||||
case R.id.addAccountButton:
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Adding account explicitly!"
|
||||
+ am.addAccountExplicitly(currentAccount, null, null),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.addAccountButtonWithUid) {
|
||||
HashMap<Integer, Integer> uidsAndVisibility = new HashMap<>();
|
||||
uidsAndVisibility.put(uid, AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||
break;
|
||||
case R.id.addAccountButtonWithVisibility:
|
||||
HashMap<String, Integer> packageAndVisibilitys = new HashMap<>();
|
||||
packageAndVisibilitys.put(packageName,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Adding account explicitly!"
|
||||
+ am.addAccountExplicitly(currentAccount, null, null,
|
||||
uidsAndVisibility)
|
||||
+ " TO: " + getPackageManager().getNameForUid(uid) + "!",
|
||||
packageAndVisibilitys)
|
||||
+ " with visibility for " + packageName + "!",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.removeAccount) {
|
||||
break;
|
||||
case R.id.removeAccount:
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Removing account explicitly!"
|
||||
+ am.removeAccountExplicitly(currentAccount),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (checkedOption == R.id.renameAccount) {
|
||||
break;
|
||||
case R.id.renameAccount:
|
||||
try {
|
||||
AccountManagerFuture<Account> accountRenameFuture = am.renameAccount(
|
||||
currentAccount, currentAccount.name + "1", null, null);
|
||||
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();
|
||||
Toast.makeText(getApplicationContext(), "Exception" + e,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuilder masterString = new StringBuilder();
|
||||
String uidMasterString = getAllRequesting3pUids.getText().toString();
|
||||
int[] allUids = null;
|
||||
//am.getRequestingUidsForType(getApplicationContext().getPackageName());
|
||||
if (allUids != null) {
|
||||
for (int i = 0; i < allUids.length; i++) {
|
||||
masterString.append(allUids[i] + "\n");
|
||||
if (am.getAccountVisibility(terraAccount,
|
||||
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
|
||||
masterString.append(terraAccount.name + ",");
|
||||
}
|
||||
if (am.getAccountVisibility(aquaAccount,
|
||||
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
|
||||
masterString.append(aquaAccount.name + ",");
|
||||
}
|
||||
if (am.getAccountVisibility(ventusAccount,
|
||||
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
|
||||
masterString.append(ventusAccount.name);
|
||||
}
|
||||
masterString.append("\n");
|
||||
}
|
||||
}
|
||||
if (masterString.length() > 0) {
|
||||
authStatus.setText(masterString);
|
||||
} else {
|
||||
authStatus.setText("----");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
});
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,8 @@
|
||||
</activity>
|
||||
<receiver android:name="com.example.android.pushapithirdpartyone.MessageReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.accounts.action.VISIBLE_ACCOUNTS_CHANGED"/>
|
||||
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<meta-data
|
||||
android:name="android.accounts.SupportedAccountTypes"
|
||||
android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -68,25 +68,6 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="----"
|
||||
android:id="@+id/logintypesregistered"
|
||||
android:layout_below="@+id/logintypesregisteredtext"
|
||||
android:layout_alignLeft="@+id/logintypesregisteredtext"
|
||||
android:layout_alignStart="@+id/logintypesregisteredtext" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Accounts Registered to Support"
|
||||
android:id="@+id/logintypesregisteredtext"
|
||||
android:layout_marginTop="58dp"
|
||||
android:layout_below="@+id/getvisibleaccounts" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.AuthenticatorDescription;
|
||||
import android.accounts.OnAccountsUpdateListener;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
@@ -40,15 +41,29 @@ import android.widget.ToggleButton;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private static AccountManager am;
|
||||
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
|
||||
private static final String TAG = "PushApiTestAppOne";
|
||||
private static AccountManager am;
|
||||
private static OnAccountsUpdateListener mListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
am = AccountManager.get(getApplicationContext());
|
||||
final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered);
|
||||
mListener = new OnAccountsUpdateListener() {
|
||||
@Override
|
||||
public void onAccountsUpdated(Account[] accounts) {
|
||||
Log.i(TAG, "onAccountsUpdated is called:");
|
||||
if (accounts != null) {
|
||||
for (Account account : accounts) {
|
||||
Log.i(TAG, "visible account: " + account);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
am.addOnAccountsUpdatedListener(mListener, null, false,
|
||||
new String[] {"com.example.android.pushapiauthenticator", "com.google"});
|
||||
final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts);
|
||||
final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts);
|
||||
final Toast notifOn =
|
||||
@@ -58,7 +73,8 @@ public class MainActivity extends Activity {
|
||||
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"
|
||||
+ "\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")
|
||||
+ " tests, use cases, and proof of concept of Account Discovery API!\n")
|
||||
.setTitle("WELCOME")
|
||||
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
@@ -67,36 +83,9 @@ public class MainActivity extends Activity {
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
String supportedPackages = "";
|
||||
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("PushApiTestAppOne", "Failed to load meta-data, NameNotFound: " + e.getMessage());
|
||||
} catch (NullPointerException e) {
|
||||
Log.e("PushApiTestAppOne", "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++) {
|
||||
masterString.append(manifestSupportedAccountTypes[i] + "\n");
|
||||
}
|
||||
if (masterString.length() > 0) {
|
||||
loginTypesRegistered.setText(masterString);
|
||||
} 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++) {
|
||||
@@ -116,6 +105,12 @@ public class MainActivity extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
am.removeOnAccountsUpdatedListener(mListener);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
|
||||
@@ -123,7 +118,6 @@ public class MainActivity extends Activity {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -21,15 +21,11 @@ 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 = "PushApiTestAppOne";
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Toast.makeText(context,
|
||||
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
|
||||
Toast.LENGTH_LONG).show();
|
||||
Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
|
||||
Log.i(TAG, "LOGIN_ACCOUNTS_CHANGED Broadcast received");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,8 @@
|
||||
</activity>
|
||||
<receiver android:name="com.example.android.pushapithirdpartytwo.MessageReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.accounts.action.VISIBLE_ACCOUNTS_CHANGED"/>
|
||||
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<meta-data
|
||||
android:name="android.accounts.SupportedAccountTypes"
|
||||
android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -68,25 +68,6 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="----"
|
||||
android:id="@+id/logintypesregistered"
|
||||
android:layout_below="@+id/logintypesregisteredtext"
|
||||
android:layout_alignLeft="@+id/logintypesregisteredtext"
|
||||
android:layout_alignStart="@+id/logintypesregisteredtext" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Accounts Registered to Support"
|
||||
android:id="@+id/logintypesregisteredtext"
|
||||
android:layout_marginTop="58dp"
|
||||
android:layout_below="@+id/getvisibleaccounts" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
@@ -21,6 +21,7 @@ import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.AuthenticatorDescription;
|
||||
import android.accounts.OnAccountsUpdateListener;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
@@ -38,22 +39,31 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
/**
|
||||
* A minimal "Hello, World!" application.
|
||||
*/
|
||||
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;
|
||||
private static final String TAG = "PushApiTestAppTwo";
|
||||
private static AccountManager am;
|
||||
private static OnAccountsUpdateListener mListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
am = AccountManager.get(getApplicationContext());
|
||||
final TextView loginTypesRegistered = (TextView) findViewById(R.id.logintypesregistered);
|
||||
mListener = new OnAccountsUpdateListener() {
|
||||
@Override
|
||||
public void onAccountsUpdated(Account[] accounts) {
|
||||
Log.i(TAG, "onAccountsUpdated is called:");
|
||||
if (accounts != null) {
|
||||
for (Account account : accounts) {
|
||||
Log.i(TAG, "visible account: " + account);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
am.addOnAccountsUpdatedListener(mListener, null, false,
|
||||
new String[] {"com.example.android.pushapiauthenticator"});
|
||||
final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts);
|
||||
final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts);
|
||||
final Toast notifOn =
|
||||
@@ -61,9 +71,10 @@ public class MainActivity extends Activity {
|
||||
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 2.\nPlease make sure you have:\n\n1. Test App 2\n"
|
||||
builder.setMessage("Welcome to Test App 2.\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")
|
||||
+ " tests, use cases, and proof of concept of Account Discovery API!\n")
|
||||
.setTitle("WELCOME")
|
||||
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
@@ -72,27 +83,6 @@ public class MainActivity extends Activity {
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
String supportedPackages = "";
|
||||
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());
|
||||
} 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++) {
|
||||
masterString.append(manifestSupportedAccountTypes[i] + "\n");
|
||||
}
|
||||
if (masterString.length() > 0) {
|
||||
loginTypesRegistered.setText(masterString);
|
||||
} else {
|
||||
loginTypesRegistered.setText("----");
|
||||
}
|
||||
getVisibleAccounts.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -114,4 +104,23 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
am.removeOnAccountsUpdatedListener(mListener);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@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();
|
||||
} else if (resultCode == RESULT_CANCELED) {
|
||||
Toast.makeText(this, "No account was chosen", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,11 @@ 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 = "PushApiTestAppTwo";
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Toast.makeText(context,
|
||||
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
|
||||
Toast.LENGTH_LONG).show();
|
||||
Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
|
||||
Log.i(TAG, "LOGIN_ACCOUNTS_CHANGED Broadcast received");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user