summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorTejas Khorana <khorana@google.com>2016-07-21 00:28:22 -0700
committerTejas Khorana <khorana@google.com>2016-08-04 15:17:40 -0700
commitfe23a4463e35992598c469d0543f4d13247dbcc2 (patch)
treebb8ed9e65895a7301ade204946718a36b21cd7eb /apps
parent9aea26cf1bdca6375ad86c05b7d509b968e44755 (diff)
downloadandroid_development-fe23a4463e35992598c469d0543f4d13247dbcc2.tar.gz
android_development-fe23a4463e35992598c469d0543f4d13247dbcc2.tar.bz2
android_development-fe23a4463e35992598c469d0543f4d13247dbcc2.zip
Test Applications Demonstrating Push API
Applications that demonstrate the usage of Push API. Change-Id: I4a2ace230d7ac7f699c998c0df96cf95f2e85a85
Diffstat (limited to 'apps')
-rw-r--r--apps/PushApiAuthenticator/Android.mk18
-rw-r--r--apps/PushApiAuthenticator/AndroidManifest.xml41
-rw-r--r--apps/PushApiAuthenticator/res/drawable/push.pngbin0 -> 31299 bytes
-rw-r--r--apps/PushApiAuthenticator/res/layout/activity_main.xml246
-rw-r--r--apps/PushApiAuthenticator/res/xml/auth_account_preferences.xml45
-rw-r--r--apps/PushApiAuthenticator/res/xml/authenticator.xml25
-rw-r--r--apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MainActivity.java217
-rw-r--r--apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticator.java69
-rw-r--r--apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticatorService.java32
-rw-r--r--apps/PushApiTestAppOne/Android.mk18
-rw-r--r--apps/PushApiTestAppOne/AndroidManifest.xml37
-rw-r--r--apps/PushApiTestAppOne/res/drawable/push.pngbin0 -> 31299 bytes
-rw-r--r--apps/PushApiTestAppOne/res/layout/activity_main.xml92
-rw-r--r--apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MainActivity.java112
-rw-r--r--apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java31
-rw-r--r--apps/PushApiTestAppTwo/Android.mk18
-rw-r--r--apps/PushApiTestAppTwo/AndroidManifest.xml37
-rw-r--r--apps/PushApiTestAppTwo/res/drawable/push.pngbin0 -> 31299 bytes
-rw-r--r--apps/PushApiTestAppTwo/res/layout/activity_main.xml106
-rw-r--r--apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java116
-rw-r--r--apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java31
21 files changed, 1291 insertions, 0 deletions
diff --git a/apps/PushApiAuthenticator/Android.mk b/apps/PushApiAuthenticator/Android.mk
new file mode 100644
index 000000000..8616882b6
--- /dev/null
+++ b/apps/PushApiAuthenticator/Android.mk
@@ -0,0 +1,18 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := PushApiAuthenticator
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH)) \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/AndroidManifest.xml b/apps/PushApiAuthenticator/AndroidManifest.xml
new file mode 100644
index 000000000..7628a6b68
--- /dev/null
+++ b/apps/PushApiAuthenticator/AndroidManifest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.pushapiauthenticator">
+ <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
+ <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+ <application android:label="Auth Tester" android:icon="@drawable/push">
+ <activity android:name="MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <service
+ android:name=".MyAccountAuthenticatorService"
+ android:exported="true">
+ <intent-filter>
+ <action
+ android:name="android.accounts.AccountAuthenticator" />
+ </intent-filter>
+ <meta-data
+ android:name="android.accounts.AccountAuthenticator"
+ android:resource="@xml/authenticator" />
+ </service>
+ </application>
+</manifest> \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/res/drawable/push.png b/apps/PushApiAuthenticator/res/drawable/push.png
new file mode 100644
index 000000000..d34e3360c
--- /dev/null
+++ b/apps/PushApiAuthenticator/res/drawable/push.png
Binary files differ
diff --git a/apps/PushApiAuthenticator/res/layout/activity_main.xml b/apps/PushApiAuthenticator/res/layout/activity_main.xml
new file mode 100644
index 000000000..52c17ea72
--- /dev/null
+++ b/apps/PushApiAuthenticator/res/layout/activity_main.xml
@@ -0,0 +1,246 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#EE6161"
+ android:orientation="vertical"
+ android:fillViewport="false">
+
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="16dp"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp"
+ android:paddingTop="16dp">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="All Requesting 3Ps"
+ android:id="@+id/textView7"
+ android:layout_below="@+id/textView3"
+ android:layout_alignLeft="@+id/textView8"
+ android:layout_alignStart="@+id/textView8"
+ android:layout_marginTop="24dp" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="UIDs"
+ 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: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"
+ android:layout_height="wrap_content"
+ android:text="GET!"
+ android:id="@+id/getallrequestingapps"
+ android:layout_alignTop="@+id/textView7"
+ android:layout_toRightOf="@+id/textView3"
+ android:layout_toEndOf="@+id/textView3" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Choose Account"
+ android:id="@+id/textView10"
+ android:layout_marginTop="57dp"
+ android:layout_below="@+id/packagesrequestingapps"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <RadioGroup
+ android:layout_width="match_parent"
+ android:layout_height="120dp"
+ android:layout_alignParentStart="true"
+ android:id="@+id/accountGroup"
+ android:layout_below="@+id/textView10"
+ android:layout_alignParentLeft="true">
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="TERRA"
+ android:id="@+id/terrabutton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="AQUA"
+ android:id="@+id/aquabutton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="VENTUS"
+ android:id="@+id/ventusbutton"
+ 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_alignParentLeft="true" />
+
+ <RadioGroup
+ android:layout_width="match_parent"
+ android:layout_height="220dp"
+ android:id="@+id/optionsGroup"
+ android:layout_below="@+id/textView11"
+ android:layout_alignParentLeft="true">
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="ADD VISIBILITY"
+ android:id="@+id/addButton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="REMOVE VISIBILITY"
+ android:id="@+id/removeButton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="GET VISIBILITY"
+ android:id="@+id/getButton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="ADD ACCOUNT (Normal)"
+ android:id="@+id/addAccountButton"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="ADD ACCOUNT EXPLICITLY w/ UID"
+ android:id="@+id/addAccountButtonWithUid"
+ android:checked="false" />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="REMOVE ACCOUNT"
+ android:id="@+id/removeAccount"
+ android:checked="false" />
+
+ </RadioGroup>
+
+ <Button
+ android:layout_marginTop="100dp"
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Go!"
+ android:id="@+id/selectoptionbutton"
+ android:layout_below="@+id/optionsGroup"
+ android:layout_alignParentLeft="true" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="STATUS:"
+ android:id="@+id/textView12"
+ android:layout_below="@+id/selectoptionbutton"
+ android:layout_alignParentLeft="true" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:text="----"
+ android:id="@+id/authenticatorstatus"
+ 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>
diff --git a/apps/PushApiAuthenticator/res/xml/auth_account_preferences.xml b/apps/PushApiAuthenticator/res/xml/auth_account_preferences.xml
new file mode 100644
index 000000000..bd7902c39
--- /dev/null
+++ b/apps/PushApiAuthenticator/res/xml/auth_account_preferences.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <PreferenceScreen
+ android:key="key1"
+ android:title="Sign-in &amp; latitude">
+ <intent android:action="com.google.android.apps.maps.LOCATION_SETTINGS" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="key3"
+ android:title="Sign-in &amp; security">
+ <intent android:action="com.google.android.gms.accountsettings.SECURITY_SETTINGS" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="key8"
+ android:title="Sign-in &amp; security">
+ <intent android:action="com.google.android.gms.accountsettings.PRIVACY_SETTINGS" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="key9"
+ android:title="Sign-in &amp; security">
+ <intent android:action=
+ "com.google.android.gms.accountsettings.ACCOUNT_PREFERENCES_SETTINGS" />
+ </PreferenceScreen>
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/res/xml/authenticator.xml b/apps/PushApiAuthenticator/res/xml/authenticator.xml
new file mode 100644
index 000000000..06cd96277
--- /dev/null
+++ b/apps/PushApiAuthenticator/res/xml/authenticator.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:accountType="com.example.android.pushapiauthenticator"
+ android:icon="@drawable/push"
+ android:smallIcon="@drawable/push"
+ android:label="This is a label"
+ android:customTokens="true"
+ android:accountPreferences="@xml/auth_account_preferences"
+/> \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MainActivity.java b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MainActivity.java
new file mode 100644
index 000000000..2d547e92f
--- /dev/null
+++ b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MainActivity.java
@@ -0,0 +1,217 @@
+/*
+ * 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.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.accounts.AuthenticatorDescription;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class MainActivity extends Activity {
+
+ private static AccountManager am;
+
+ public boolean isAccountAdded(Account a) {
+ Account[] accounts = am.getAccountsByType(getApplicationContext().getPackageName());
+ for (Account account : accounts) {
+ if (a.equals(account)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ 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 RadioGroup accountChooser = (RadioGroup) findViewById(R.id.accountGroup);
+ final RadioGroup optionChooser = (RadioGroup) findViewById(R.id.optionsGroup);
+ final EditText uidChooser = (EditText) findViewById(R.id.uidchooser);
+ 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 chooseAccountWarning = Toast.makeText(getApplicationContext(),
+ "Choose an Account!", Toast.LENGTH_SHORT);
+ final Toast chooseOptionWarning = Toast.makeText(getApplicationContext(),
+ "Choose an Option!", Toast.LENGTH_SHORT);
+
+ final String ACCOUNT_PASSWORD = "some password";
+ final Bundle ACCOUNT_BUNDLE = new Bundle();
+
+ Account terraAccount = new Account("TERRA", getPackageName());
+ Account aquaAccount = new Account("AQUA", getPackageName());
+ Account ventusAccount = new Account("VENTUS", getPackageName());
+
+ 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")
+ .setTitle("WELCOME")
+ .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ //do nothing
+ }
+ });
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+
+ getAllRequestingApps.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int[] allRequestedUids = am.getRequestingUidsForType(getApplicationContext()
+ .getPackageName());
+ if (allRequestedUids != null) {
+ 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");
+ }
+ 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;
+ int checkedAccount = accountChooser.getCheckedRadioButtonId();
+ int checkedOption = optionChooser.getCheckedRadioButtonId();
+ if (uidChooser.getText().length() == 0) {
+ enterUidWarning.show();
+ } else if (checkedAccount == -1) {
+ chooseAccountWarning.show();
+ } else if (checkedOption == -1) {
+ chooseOptionWarning.show();
+ } else {
+ //all conditions satisfied
+ if (checkedAccount == R.id.terrabutton) {
+ currentAccount = terraAccount;
+ } else if (checkedAccount == R.id.aquabutton) {
+ currentAccount = aquaAccount;
+ } else if (checkedAccount == R.id.ventusbutton) {
+ currentAccount = ventusAccount;
+ }
+ 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),
+ 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),
+ 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();
+ } 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) {
+ int[] uidsToAdd = new int[] {uid};
+ Toast.makeText(getApplicationContext(), "Adding account explicitly!"
+ + am.addAccountExplicitly(currentAccount, null, null, uidsToAdd)
+ + " 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();
+ }
+ StringBuilder masterString = new StringBuilder();
+ String uidMasterString = getAllRequesting3pUids.getText().toString();
+ int[] allUids = am.getRequestingUidsForType(getApplicationContext().
+ getPackageName());
+ if (allUids != null) {
+ for (int i = 0 ; i < allUids.length ; i++) {
+ masterString.append(allUids[i] + "\n");
+ if (am.isAccountVisible(terraAccount, allUids[i])) {
+ masterString.append(terraAccount.name + ",");
+ }
+ if (am.isAccountVisible(aquaAccount, allUids[i])) {
+ masterString.append(aquaAccount.name + ",");
+ }
+ if (am.isAccountVisible(ventusAccount, allUids[i])) {
+ masterString.append(ventusAccount.name);
+ }
+ masterString.append("\n");
+ }
+ }
+ if (masterString.length() > 0) {
+ authStatus.setText(masterString);
+ }
+ else {
+ authStatus.setText("----");
+ }
+ }
+ }
+ });
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticator.java b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticator.java
new file mode 100644
index 000000000..fa4adeba3
--- /dev/null
+++ b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticator.java
@@ -0,0 +1,69 @@
+/*
+ * 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.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.AccountManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+
+public class MyAccountAuthenticator extends AbstractAccountAuthenticator {
+
+ private final Context mContext;
+
+ public MyAccountAuthenticator(Context context) {
+ super(context);
+ mContext = context;
+ }
+
+ public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
+ String authTokenType, String[] requiredFeatures, Bundle options) {
+ return null;
+ }
+
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
+ String authTokenType, Bundle options) {
+ return null;
+ }
+
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
+ Bundle options) {
+ return null;
+ }
+
+ public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
+ return null;
+ }
+
+ public String getAuthTokenLabel(String authTokenType) {
+ return null;
+ }
+
+ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account,
+ String[] features) {
+ return null;
+ }
+
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
+ String authTokenType, Bundle options) {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticatorService.java b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticatorService.java
new file mode 100644
index 000000000..deef404f1
--- /dev/null
+++ b/apps/PushApiAuthenticator/src/com/example/android/pushapiauthenticator/MyAccountAuthenticatorService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+public class MyAccountAuthenticatorService extends Service {
+
+ private static final String TAG = "AuthenticationService";
+ private final MyAccountAuthenticator authenticator = new MyAccountAuthenticator(this);
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return authenticator.getIBinder();
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiTestAppOne/Android.mk b/apps/PushApiTestAppOne/Android.mk
new file mode 100644
index 000000000..ccd2236d6
--- /dev/null
+++ b/apps/PushApiTestAppOne/Android.mk
@@ -0,0 +1,18 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := PushApiTestAppOne
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH)) \ No newline at end of file
diff --git a/apps/PushApiTestAppOne/AndroidManifest.xml b/apps/PushApiTestAppOne/AndroidManifest.xml
new file mode 100644
index 000000000..3999fdc57
--- /dev/null
+++ b/apps/PushApiTestAppOne/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.pushapithirdpartyone">
+ <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+ <application android:label="3P App 1" android:icon="@drawable/push">
+ <activity android:name="MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <receiver android:name="com.example.android.pushapithirdpartyone.MessageReceiver">
+ <intent-filter>
+ <action android:name="android.accounts.NEW_ACCOUNT_VISIBLE"/>
+ </intent-filter>
+ </receiver>
+ <meta-data
+ android:name="android.accounts.SupportedLoginTypes"
+ android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator" />
+ </application>
+</manifest> \ No newline at end of file
diff --git a/apps/PushApiTestAppOne/res/drawable/push.png b/apps/PushApiTestAppOne/res/drawable/push.png
new file mode 100644
index 000000000..d34e3360c
--- /dev/null
+++ b/apps/PushApiTestAppOne/res/drawable/push.png
Binary files differ
diff --git a/apps/PushApiTestAppOne/res/layout/activity_main.xml b/apps/PushApiTestAppOne/res/layout/activity_main.xml
new file mode 100644
index 000000000..952e35352
--- /dev/null
+++ b/apps/PushApiTestAppOne/res/layout/activity_main.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#ADD8E6"
+ android:orientation="vertical"
+ android:fillViewport="false">
+
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/relativelayout">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Test Application One"
+ android:id="@+id/testapponetext"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="27dp" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Visible Accounts"
+ android:id="@+id/visibleaccountstext"
+ android:layout_marginTop="58dp"
+ android:layout_below="@+id/testapponetext"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:text="----"
+ android:id="@+id/visibleaccounts"
+ android:layout_below="@+id/visibleaccountstext"
+ android:layout_alignLeft="@+id/visibleaccountstext"
+ android:layout_alignStart="@+id/visibleaccountstext" />
+
+ <Button
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Get!"
+ android:id="@+id/getvisibleaccounts"
+ android:layout_alignTop="@+id/visibleaccountstext"
+ 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> \ No newline at end of file
diff --git a/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MainActivity.java b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MainActivity.java
new file mode 100644
index 000000000..7513f0b9a
--- /dev/null
+++ b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MainActivity.java
@@ -0,0 +1,112 @@
+/*
+ * 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.pushapithirdpartyone;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.accounts.AuthenticatorDescription;
+import android.app.Activity;
+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.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ToggleButton;
+
+public class MainActivity extends Activity {
+
+ private static AccountManager am;
+
+ @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);
+ 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);
+ 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")
+ .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ //do nothing
+ }
+ });
+ 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.SupportedLoginTypes");
+ } 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) {
+ 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");
+ }
+ if (masterString.length() > 0) {
+ visibleAccounts.setText(masterString);
+ }
+ else {
+ visibleAccounts.setText("----");
+ }
+ }
+ });
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java
new file mode 100644
index 000000000..21951f322
--- /dev/null
+++ b/apps/PushApiTestAppOne/src/com/example/android/pushapithirdpartyone/MessageReceiver.java
@@ -0,0 +1,31 @@
+/*
+ * 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.pushapithirdpartyone;
+
+import android.accounts.Account;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+public class MessageReceiver extends BroadcastReceiver{
+ public void onReceive(Context context, Intent intent) {
+ Account account = (Account) intent.getParcelableExtra("android.accounts.KEY_ACCOUNT");
+ Toast.makeText(context, "Account " + account.name + " received by Test App 1",
+ Toast.LENGTH_LONG).show();
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiTestAppTwo/Android.mk b/apps/PushApiTestAppTwo/Android.mk
new file mode 100644
index 000000000..a46f3f0a9
--- /dev/null
+++ b/apps/PushApiTestAppTwo/Android.mk
@@ -0,0 +1,18 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := PushApiTestAppTwo
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/apps/PushApiTestAppTwo/AndroidManifest.xml b/apps/PushApiTestAppTwo/AndroidManifest.xml
new file mode 100644
index 000000000..7f1d000cf
--- /dev/null
+++ b/apps/PushApiTestAppTwo/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.pushapithirdpartytwo">
+ <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
+ <application android:label="3P App 2" android:icon="@drawable/push">
+ <activity android:name="MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <receiver android:name="com.example.android.pushapithirdpartytwo.MessageReceiver">
+ <intent-filter>
+ <action android:name="android.accounts.NEW_ACCOUNT_VISIBLE"/>
+ </intent-filter>
+ </receiver>
+ <meta-data
+ android:name="android.accounts.SupportedLoginTypes"
+ android:value="com.google;com.whatsapp;com.example.android.pushapiauthenticator" />
+ </application>
+</manifest> \ No newline at end of file
diff --git a/apps/PushApiTestAppTwo/res/drawable/push.png b/apps/PushApiTestAppTwo/res/drawable/push.png
new file mode 100644
index 000000000..d34e3360c
--- /dev/null
+++ b/apps/PushApiTestAppTwo/res/drawable/push.png
Binary files differ
diff --git a/apps/PushApiTestAppTwo/res/layout/activity_main.xml b/apps/PushApiTestAppTwo/res/layout/activity_main.xml
new file mode 100644
index 000000000..23d3fe848
--- /dev/null
+++ b/apps/PushApiTestAppTwo/res/layout/activity_main.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#ADE6B4"
+ android:orientation="vertical"
+ android:fillViewport="false">
+
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="16dp"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp"
+ android:paddingTop="16dp"
+ android:id="@+id/relativelayout">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:text="----"
+ android:id="@+id/logintypesregistered2"
+ android:layout_below="@+id/logintypesregisteredtext"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <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_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_marginTop="34dp"
+ android:layout_below="@+id/placeholder" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Visible Accounts"
+ android:id="@+id/textView5"
+ android:layout_alignTop="@+id/getvisibleaccounts2"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:text="----"
+ android:id="@+id/visibleaccounts2"
+ android:layout_below="@+id/getvisibleaccounts2"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <EditText
+ android:layout_width="1dp"
+ android:layout_height="wrap_content"
+ android:id="@+id/placeholder"
+ android:layout_alignRight="@+id/logintypesregistered2"
+ android:layout_alignEnd="@+id/logintypesregistered2"
+ android:layout_below="@+id/visibleaccounts2" />
+
+ <Button
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Get!"
+ android:id="@+id/getvisibleaccounts2"
+ android:layout_below="@+id/textView"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentEnd="true"
+ android:layout_marginTop="37dp" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Test Application Two"
+ android:id="@+id/textView"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true" />
+
+ </RelativeLayout>
+
+</ScrollView>
diff --git a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java
new file mode 100644
index 000000000..2288d851b
--- /dev/null
+++ b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MainActivity.java
@@ -0,0 +1,116 @@
+/*
+ * 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.pushapithirdpartytwo;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.accounts.AuthenticatorDescription;
+import android.app.Activity;
+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.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.CompoundButton;
+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;
+
+ @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.logintypesregistered2);
+ final TextView visibleAccounts = (TextView) findViewById(R.id.visibleaccounts2);
+ final Button getVisibleAccounts = (Button) findViewById(R.id.getvisibleaccounts2);
+ 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")
+ .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ //do nothing
+ }
+ });
+ 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.SupportedLoginTypes");
+ } 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) {
+ 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");
+ }
+ if (masterString.length() > 0) {
+ visibleAccounts.setText(masterString);
+ }
+ else {
+ visibleAccounts.setText("----");
+ }
+ }
+ });
+ }
+} \ No newline at end of file
diff --git a/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java
new file mode 100644
index 000000000..496df1be9
--- /dev/null
+++ b/apps/PushApiTestAppTwo/src/com/example/android/pushapithirdpartytwo/MessageReceiver.java
@@ -0,0 +1,31 @@
+/*
+ * 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.pushapithirdpartytwo;
+
+import android.accounts.Account;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+public class MessageReceiver extends BroadcastReceiver{
+ public void onReceive(Context context, Intent intent) {
+ Account account = (Account) intent.getParcelableExtra("android.accounts.KEY_ACCOUNT");
+ Toast.makeText(context, "Account " + account.name + " received by Test App 2",
+ Toast.LENGTH_LONG).show();
+ }
+} \ No newline at end of file