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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:text="UIDs"
|
android:text="pushapi packages: "
|
||||||
android:id="@+id/textView8"
|
android:id="@+id/textView8"
|
||||||
android:layout_below="@+id/textView7"
|
android:layout_below="@+id/textView7"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:text="-----"
|
android:text="-----"
|
||||||
android:id="@+id/uidsrequestingapps"
|
android:id="@+id/requestingapps"
|
||||||
|
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/textView8"
|
android:layout_below="@+id/textView8"
|
||||||
android:layout_toRightOf="@+id/authenticatorstatus" />
|
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
|
<Button
|
||||||
style="?android:attr/buttonStyleSmall"
|
style="?android:attr/buttonStyleSmall"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -91,8 +70,8 @@
|
|||||||
android:text="GET!"
|
android:text="GET!"
|
||||||
android:id="@+id/getallrequestingapps"
|
android:id="@+id/getallrequestingapps"
|
||||||
android:layout_alignTop="@+id/textView7"
|
android:layout_alignTop="@+id/textView7"
|
||||||
android:layout_toRightOf="@+id/textView3"
|
android:layout_toRightOf="@+id/textView7"
|
||||||
android:layout_toEndOf="@+id/textView3" />
|
android:layout_toEndOf="@+id/textView7" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -101,7 +80,7 @@
|
|||||||
android:text="Choose Account"
|
android:text="Choose Account"
|
||||||
android:id="@+id/textView10"
|
android:id="@+id/textView10"
|
||||||
android:layout_marginTop="57dp"
|
android:layout_marginTop="57dp"
|
||||||
android:layout_below="@+id/packagesrequestingapps"
|
android:layout_below="@+id/requestingapps"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true" />
|
android:layout_alignParentStart="true" />
|
||||||
|
|
||||||
@@ -135,13 +114,44 @@
|
|||||||
android:checked="false" />
|
android:checked="false" />
|
||||||
</RadioGroup>
|
</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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:text="Options"
|
android:text="Options"
|
||||||
android:id="@+id/textView11"
|
android:id="@+id/textView11"
|
||||||
android:layout_below="@+id/accountGroup"
|
android:layout_below="@+id/packagesChooser"
|
||||||
android:layout_alignParentLeft="true" />
|
android:layout_alignParentLeft="true" />
|
||||||
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
@@ -154,21 +164,21 @@
|
|||||||
<RadioButton
|
<RadioButton
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="SET VISIBLE (MANAGED)"
|
android:text="SET UM_VISIBLE (2)"
|
||||||
android:id="@+id/visibleButton"
|
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="SET NOT_VISIBLE (MANAGED)"
|
android:text="SET UM_NOT_VISIBLE(4)"
|
||||||
android:id="@+id/notVisibleButton"
|
android:id="@+id/notVisibleButton"
|
||||||
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="SET NOT_VISIBLE"
|
android:text="SET NOT_VISIBLE(3)"
|
||||||
android:id="@+id/forcedNotVisibleButton"
|
android:id="@+id/forcedNotVisibleButton"
|
||||||
android:checked="false" />
|
android:checked="false" />
|
||||||
|
|
||||||
@@ -189,8 +199,8 @@
|
|||||||
<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 ACCOUNT EXPLICITLY w/ UID"
|
android:text="ADD ACCOUNT (With visibility)"
|
||||||
android:id="@+id/addAccountButtonWithUid"
|
android:id="@+id/addAccountButtonWithVisibility"
|
||||||
android:checked="false" />
|
android:checked="false" />
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
@@ -237,24 +247,6 @@
|
|||||||
android:layout_below="@+id/textView12"
|
android:layout_below="@+id/textView12"
|
||||||
android:layout_alignParentLeft="true" />
|
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>
|
</RelativeLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* 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"); you may not use this file except
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* in compliance with the License. You may obtain a copy of the License at
|
* 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
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* or implied. See the License for the specific language governing permissions and limitations under
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* the License.
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package com.example.android.pushapiauthenticator;
|
package com.example.android.pushapiauthenticator;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
@@ -24,6 +27,8 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -35,6 +40,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
@@ -57,20 +63,18 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
am = AccountManager.get(getApplicationContext());
|
am = AccountManager.get(getApplicationContext());
|
||||||
final Button getAllRequestingApps = (Button) findViewById(R.id.getallrequestingapps);
|
final Button getAllRequestingApps = (Button) findViewById(R.id.getallrequestingapps);
|
||||||
final TextView getAllRequesting3pUids = (TextView) findViewById(R.id.uidsrequestingapps);
|
final TextView getAllRequesting3pUids = (TextView) findViewById(R.id.requestingapps);
|
||||||
final TextView getAllRequesting3pPackages =
|
|
||||||
(TextView) findViewById(R.id.packagesrequestingapps);
|
|
||||||
|
|
||||||
final RadioGroup accountChooser = (RadioGroup) findViewById(R.id.accountGroup);
|
final RadioGroup accountChooser = (RadioGroup) findViewById(R.id.accountGroup);
|
||||||
final RadioGroup optionChooser = (RadioGroup) findViewById(R.id.optionsGroup);
|
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 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 =
|
final Toast hitGet =
|
||||||
Toast.makeText(getApplicationContext(), "Hit the GET Button!", Toast.LENGTH_SHORT);
|
Toast.makeText(getApplicationContext(), "Hit the GET Button!", Toast.LENGTH_SHORT);
|
||||||
final Toast enterUidWarning =
|
final Toast enterPackageName = Toast.makeText(getApplicationContext(),
|
||||||
Toast.makeText(getApplicationContext(), "Enter a UID!", Toast.LENGTH_SHORT);
|
"Choose a packageName!", Toast.LENGTH_SHORT);
|
||||||
final Toast chooseAccountWarning =
|
final Toast chooseAccountWarning =
|
||||||
Toast.makeText(getApplicationContext(), "Choose an Account!", Toast.LENGTH_SHORT);
|
Toast.makeText(getApplicationContext(), "Choose an Account!", Toast.LENGTH_SHORT);
|
||||||
final Toast chooseOptionWarning =
|
final Toast chooseOptionWarning =
|
||||||
@@ -86,7 +90,7 @@ 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")
|
+ " provide tests, use cases, and proof of concept of Account Discovery API!\n")
|
||||||
.setTitle("WELCOME")
|
.setTitle("WELCOME")
|
||||||
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -101,42 +105,33 @@ 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 = null;
|
List<ApplicationInfo> list = getPackageManager().getInstalledApplications(
|
||||||
// TODO remove uid part
|
PackageManager.GET_META_DATA);
|
||||||
// am.getRequestingUidsForType(getApplicationContext().getPackageName());
|
StringBuilder uidMasterString = new StringBuilder();
|
||||||
if (allRequestedUids != null) {
|
StringBuilder packageMasterString = new StringBuilder();
|
||||||
StringBuilder uidMasterString = new StringBuilder();
|
for (ApplicationInfo ai :list) {
|
||||||
StringBuilder packageMasterString = new StringBuilder();
|
String label = (String) ai.processName;
|
||||||
for (int i = 0; i < allRequestedUids.length; i++) {
|
if (label.contains("pushapi")) {
|
||||||
uidMasterString.append(allRequestedUids[i] + ",\n\n");
|
uidMasterString.append(label + "\n");
|
||||||
packageMasterString.append(
|
|
||||||
getPackageManager().getNameForUid(allRequestedUids[i]) + ",\n\n");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (uidMasterString.length() > 0) {
|
if (uidMasterString.length() > 0) {
|
||||||
getAllRequesting3pUids.setText(uidMasterString);
|
getAllRequesting3pUids.setText(uidMasterString);
|
||||||
} else {
|
} else {
|
||||||
getAllRequesting3pUids.setText("----");
|
getAllRequesting3pUids.setText("----");
|
||||||
}
|
}
|
||||||
if (packageMasterString.length() > 0) {
|
|
||||||
getAllRequesting3pPackages.setText(packageMasterString);
|
|
||||||
} else {
|
|
||||||
getAllRequesting3pPackages.setText("----");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getAllRequesting3pPackages.setText("----");
|
|
||||||
getAllRequesting3pUids.setText("----");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
selectOption.setOnClickListener(new View.OnClickListener() {
|
selectOption.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
/*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) {
|
int checkedApp = packagesChooser.getCheckedRadioButtonId();
|
||||||
enterUidWarning.show();
|
if (checkedApp == -1) {
|
||||||
|
enterPackageName.show();
|
||||||
} else if (checkedAccount == -1) {
|
} else if (checkedAccount == -1) {
|
||||||
chooseAccountWarning.show();
|
chooseAccountWarning.show();
|
||||||
} else if (checkedOption == -1) {
|
} else if (checkedOption == -1) {
|
||||||
@@ -150,96 +145,80 @@ public class MainActivity extends Activity {
|
|||||||
} else if (checkedAccount == R.id.ventusbutton) {
|
} else if (checkedAccount == R.id.ventusbutton) {
|
||||||
currentAccount = ventusAccount;
|
currentAccount = ventusAccount;
|
||||||
}
|
}
|
||||||
String uidstr = uidChooser.getText().toString();
|
String packageName =
|
||||||
int uid = Integer.parseInt(uidstr);
|
((RadioButton) findViewById(checkedApp)).getText().toString();
|
||||||
if (checkedOption == R.id.visibleButton) {
|
switch (checkedOption) {
|
||||||
am.setAccountVisibility(currentAccount, uid,
|
case R.id.visibleButton:
|
||||||
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
am.setAccountVisibility(currentAccount, packageName,
|
||||||
Toast.makeText(getApplicationContext(),
|
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||||
"Giving visibility of " + currentAccount.name + " to "
|
Toast.makeText(
|
||||||
+ getPackageManager().getNameForUid(uid),
|
getApplicationContext(), "Set UM_VISIBLE(2) "
|
||||||
Toast.LENGTH_SHORT).show();
|
+ currentAccount.name + " to " + packageName,
|
||||||
} else if (checkedOption == R.id.notVisibleButton) {
|
Toast.LENGTH_SHORT).show();
|
||||||
am.setAccountVisibility(currentAccount, uid,
|
break;
|
||||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
case R.id.notVisibleButton:
|
||||||
Toast.makeText(getApplicationContext(),
|
am.setAccountVisibility(currentAccount, packageName,
|
||||||
"Removing visibility of " + currentAccount.name + " to "
|
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||||
+ getPackageManager().getNameForUid(uid),
|
Toast.makeText(
|
||||||
Toast.LENGTH_SHORT).show();
|
getApplicationContext(), "Set UM_NOT_VISIBLE(4) "
|
||||||
} else if (checkedOption == R.id.forcedNotVisibleButton) {
|
+ currentAccount.name + " to " + packageName,
|
||||||
am.setAccountVisibility(currentAccount, uid,
|
Toast.LENGTH_SHORT).show();
|
||||||
AccountManager.VISIBILITY_NOT_VISIBLE);
|
break;
|
||||||
Toast.makeText(getApplicationContext(),
|
case R.id.forcedNotVisibleButton:
|
||||||
"Removing visibility (not managed) of " + currentAccount.name
|
am.setAccountVisibility(currentAccount, packageName,
|
||||||
+ " to " + getPackageManager().getNameForUid(uid),
|
AccountManager.VISIBILITY_NOT_VISIBLE);
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.makeText(
|
||||||
} else if (checkedOption == R.id.getButton) {
|
getApplicationContext(), "Removing visibility(3) "
|
||||||
Toast.makeText(getApplicationContext(),
|
+ currentAccount.name + " of " + packageName,
|
||||||
"Is " + currentAccount.name + " visible to "
|
Toast.LENGTH_SHORT).show();
|
||||||
+ getPackageManager().getNameForUid(uid) + "?\n"
|
break;
|
||||||
+ am.getAccountVisibility(currentAccount, uid),
|
case R.id.getButton:
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
} else if (checkedOption == 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);
|
|
||||||
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.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(),
|
Toast.makeText(getApplicationContext(),
|
||||||
"New account name " + renamedAccount, Toast.LENGTH_SHORT)
|
"Is " + currentAccount.name + " visible to " + packageName
|
||||||
.show();
|
+ "?\n"
|
||||||
} catch (Exception e) {
|
+ am.getAccountVisibility(currentAccount, packageName),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
case R.id.addAccountButton:
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
"Exception" + e, Toast.LENGTH_SHORT)
|
"Adding account explicitly!"
|
||||||
.show();
|
+ am.addAccountExplicitly(currentAccount, null, null),
|
||||||
}
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
break;
|
||||||
StringBuilder masterString = new StringBuilder();
|
case R.id.addAccountButtonWithVisibility:
|
||||||
String uidMasterString = getAllRequesting3pUids.getText().toString();
|
HashMap<String, Integer> packageAndVisibilitys = new HashMap<>();
|
||||||
int[] allUids = null;
|
packageAndVisibilitys.put(packageName,
|
||||||
//am.getRequestingUidsForType(getApplicationContext().getPackageName());
|
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||||
if (allUids != null) {
|
Toast.makeText(getApplicationContext(),
|
||||||
for (int i = 0; i < allUids.length; i++) {
|
"Adding account explicitly!"
|
||||||
masterString.append(allUids[i] + "\n");
|
+ am.addAccountExplicitly(currentAccount, null, null,
|
||||||
if (am.getAccountVisibility(terraAccount,
|
packageAndVisibilitys)
|
||||||
allUids[i]) == AccountManager.VISIBILITY_USER_MANAGED_VISIBLE) {
|
+ " with visibility for " + packageName + "!",
|
||||||
masterString.append(terraAccount.name + ",");
|
Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
case R.id.removeAccount:
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
"Removing account explicitly!"
|
||||||
|
+ am.removeAccountExplicitly(currentAccount),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
case 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();
|
||||||
}
|
}
|
||||||
if (am.getAccountVisibility(aquaAccount,
|
break;
|
||||||
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>
|
</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.action.VISIBLE_ACCOUNTS_CHANGED"/>
|
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<meta-data
|
|
||||||
android:name="android.accounts.SupportedAccountTypes"
|
|
||||||
android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator"/>
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -68,25 +68,6 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentEnd="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>
|
</RelativeLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.accounts.AccountManager;
|
|||||||
import android.accounts.AccountManagerCallback;
|
import android.accounts.AccountManagerCallback;
|
||||||
import android.accounts.AccountManagerFuture;
|
import android.accounts.AccountManagerFuture;
|
||||||
import android.accounts.AuthenticatorDescription;
|
import android.accounts.AuthenticatorDescription;
|
||||||
|
import android.accounts.OnAccountsUpdateListener;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -40,15 +41,29 @@ import android.widget.ToggleButton;
|
|||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
private static AccountManager am;
|
|
||||||
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
|
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
|
||||||
|
private static final String TAG = "PushApiTestAppOne";
|
||||||
|
private static AccountManager am;
|
||||||
|
private static OnAccountsUpdateListener mListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
am = AccountManager.get(getApplicationContext());
|
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 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 =
|
final Toast notifOn =
|
||||||
@@ -58,7 +73,8 @@ public class MainActivity extends Activity {
|
|||||||
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").setTitle("WELCOME")
|
+ " tests, use cases, and proof of concept of Account Discovery API!\n")
|
||||||
|
.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) {
|
||||||
@@ -67,36 +83,9 @@ public class MainActivity extends Activity {
|
|||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
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() {
|
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++) {
|
||||||
@@ -116,6 +105,12 @@ public class MainActivity extends Activity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
am.removeOnAccountsUpdatedListener(mListener);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
|
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
|
||||||
@@ -123,7 +118,6 @@ public class MainActivity extends Activity {
|
|||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
Toast.makeText(this, data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE),
|
Toast.makeText(this, data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
// data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
|
||||||
} else if (resultCode == RESULT_CANCELED) {
|
} else if (resultCode == RESULT_CANCELED) {
|
||||||
Toast.makeText(this, "No account was chosen", Toast.LENGTH_LONG).show();
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class MessageReceiver extends BroadcastReceiver {
|
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,
|
Log.i(TAG, "LOGIN_ACCOUNTS_CHANGED Broadcast received");
|
||||||
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,8 @@
|
|||||||
</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.action.VISIBLE_ACCOUNTS_CHANGED"/>
|
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<meta-data
|
|
||||||
android:name="android.accounts.SupportedAccountTypes"
|
|
||||||
android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator" />
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -68,25 +68,6 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentEnd="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>
|
</RelativeLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.accounts.AccountManager;
|
|||||||
import android.accounts.AccountManagerCallback;
|
import android.accounts.AccountManagerCallback;
|
||||||
import android.accounts.AccountManagerFuture;
|
import android.accounts.AccountManagerFuture;
|
||||||
import android.accounts.AuthenticatorDescription;
|
import android.accounts.AuthenticatorDescription;
|
||||||
|
import android.accounts.OnAccountsUpdateListener;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -38,22 +39,31 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
/**
|
|
||||||
* A minimal "Hello, World!" application.
|
|
||||||
*/
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
/**
|
|
||||||
* Called with the activity is first created.
|
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
|
||||||
*/
|
private static final String TAG = "PushApiTestAppTwo";
|
||||||
private static AccountManager am;
|
private static AccountManager am;
|
||||||
private static final int REQUEST_CODE_PICK_ACCOUNT = 0;
|
private static OnAccountsUpdateListener mListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
am = AccountManager.get(getApplicationContext());
|
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 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 =
|
final Toast notifOn =
|
||||||
@@ -61,9 +71,10 @@ public class MainActivity extends Activity {
|
|||||||
final Toast notifOff =
|
final Toast notifOff =
|
||||||
Toast.makeText(getApplicationContext(), "Notifs Turned Off!", 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 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"
|
+ "\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() {
|
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
@@ -72,27 +83,6 @@ public class MainActivity extends Activity {
|
|||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
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() {
|
getVisibleAccounts.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class MessageReceiver extends BroadcastReceiver {
|
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,
|
Log.i(TAG, "LOGIN_ACCOUNTS_CHANGED Broadcast received");
|
||||||
"android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received",
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
Log.i(TAG, "android.accounts.action.VISIBLE_ACCOUNTS_CHANGED Broadcast received");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user