Attempting to add new Corp App to demo Global Proxy.
Making ApiDemos device admin able to set the Global Proxy. Change-Id: I565ccf5d05b1c7d775aea968e99e04894c3f8b64
This commit is contained in:
@@ -208,6 +208,31 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout android:orientation="vertical" android:gravity="center_horizontal"
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<EditText android:id="@+id/proxyhost"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:hint="@string/proxyhost_hint">
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
<EditText android:id="@+id/proxylist"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:hint="@string/proxylist_hint">
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
<Button android:id="@+id/set_proxy"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:text="@string/set_proxy_label">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -512,6 +512,9 @@
|
|||||||
<string name="wipe_data">Wipe Data</string>
|
<string name="wipe_data">Wipe Data</string>
|
||||||
<string name="timeout_hint">Max screen timeout</string>
|
<string name="timeout_hint">Max screen timeout</string>
|
||||||
<string name="set_timeout_label">Set Timeout</string>
|
<string name="set_timeout_label">Set Timeout</string>
|
||||||
|
<string name="proxyhost_hint">Global proxyhost:port</string>
|
||||||
|
<string name="proxylist_hint">No proxy for domain1,domain2</string>
|
||||||
|
<string name="set_proxy_label">Set Global Proxy</string>
|
||||||
|
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- app/voice recognition examples strings -->
|
<!-- app/voice recognition examples strings -->
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<reset-password />
|
<reset-password />
|
||||||
<force-lock />
|
<force-lock />
|
||||||
<wipe-data />
|
<wipe-data />
|
||||||
|
<set-global-proxy />
|
||||||
</uses-policies>
|
</uses-policies>
|
||||||
</device-admin>
|
</device-admin>
|
||||||
<!-- END_INCLUDE(meta_data) -->
|
<!-- END_INCLUDE(meta_data) -->
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ import android.widget.Spinner;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example of a do-nothing admin class. When enabled, it lets you control
|
* Example of a do-nothing admin class. When enabled, it lets you control
|
||||||
* some of its policy and reports when there is interesting activity.
|
* some of its policy and reports when there is interesting activity.
|
||||||
@@ -148,6 +153,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
|
|
||||||
private EditText mTimeout;
|
private EditText mTimeout;
|
||||||
|
|
||||||
|
EditText mProxyHost;
|
||||||
|
EditText mProxyList;
|
||||||
|
Button mProxyButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -318,6 +327,11 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mTimeout = (EditText) findViewById(R.id.timeout);
|
mTimeout = (EditText) findViewById(R.id.timeout);
|
||||||
mTimeoutButton = (Button) findViewById(R.id.set_timeout);
|
mTimeoutButton = (Button) findViewById(R.id.set_timeout);
|
||||||
mTimeoutButton.setOnClickListener(mSetTimeoutListener);
|
mTimeoutButton.setOnClickListener(mSetTimeoutListener);
|
||||||
|
|
||||||
|
mProxyHost = (EditText) findViewById(R.id.proxyhost);
|
||||||
|
mProxyList = (EditText) findViewById(R.id.proxylist);
|
||||||
|
mProxyButton = (Button) findViewById(R.id.set_proxy);
|
||||||
|
mProxyButton.setOnClickListener(mSetProxyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateButtonStates() {
|
void updateButtonStates() {
|
||||||
@@ -614,5 +628,49 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private OnClickListener mSetProxyListener = new OnClickListener() {
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean active = mDPM.isAdminActive(mDeviceAdminSample);
|
||||||
|
String proxySpec = mProxyHost.getText().toString();
|
||||||
|
String proxyList = mProxyList.getText().toString();
|
||||||
|
Proxy instProxy;
|
||||||
|
List<String> exclList;
|
||||||
|
|
||||||
|
if ((proxySpec.length() == 0) || (proxySpec == null)) {
|
||||||
|
instProxy = Proxy.NO_PROXY;
|
||||||
|
} else {
|
||||||
|
String[] proxyComponents = proxySpec.split(":");
|
||||||
|
if (proxyComponents.length != 2) {
|
||||||
|
Toast.makeText(Controller.this, "Wrong proxy specification.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
instProxy = new Proxy(Proxy.Type.HTTP,
|
||||||
|
new InetSocketAddress(proxyComponents[0],
|
||||||
|
Integer.parseInt(proxyComponents[1])));
|
||||||
|
}
|
||||||
|
if ((proxyList == null) || (proxyList.length() == 0)) {
|
||||||
|
exclList = null;
|
||||||
|
} else {
|
||||||
|
String[] listDoms = proxyList.split(",");
|
||||||
|
if (listDoms.length == 0) {
|
||||||
|
Toast.makeText(Controller.this, "Wrong exclusion list format.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
exclList = Arrays.asList(listDoms);
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
mDPM.setGlobalProxy(mDeviceAdminSample, instProxy, exclList);
|
||||||
|
ComponentName proxyAdmin = mDPM.getGlobalProxyAdmin();
|
||||||
|
if ((proxyAdmin != null) && (proxyAdmin.equals(mDeviceAdminSample))) {
|
||||||
|
Toast.makeText(Controller.this, "Global Proxy set by device admin.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
samples/CorpApp/Android.mk
Normal file
17
samples/CorpApp/Android.mk
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
LOCAL_PATH:= $(call my-dir)
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE_TAGS := samples
|
||||||
|
|
||||||
|
# Only compile source java files in this apk.
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := CorpApp
|
||||||
|
|
||||||
|
LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
||||||
|
|
||||||
|
# Use the following include to make our test apk.
|
||||||
|
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||||
|
|
||||||
44
samples/CorpApp/AndroidManifest.xml
Normal file
44
samples/CorpApp/AndroidManifest.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Declare the contents of this Android application. The namespace
|
||||||
|
attribute brings in the Android platform namespace, and the package
|
||||||
|
supplies a unique name for the application. When writing your
|
||||||
|
own application, the package name must be changed from "com.example.*"
|
||||||
|
to come from a domain that you own or have control over. -->
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.android.corpapp">
|
||||||
|
<application android:label="CorporateDeviceAdminDemoApp">
|
||||||
|
<activity android:name="CorpAppActivity"
|
||||||
|
android:label="@string/corp_app_activity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<receiver android:name=".app.CorpDeviceAdmin"
|
||||||
|
android:label="@string/corp_app_admin"
|
||||||
|
android:description="@string/corp_device_admin_description"
|
||||||
|
android:permission="android.permission.BIND_DEVICE_ADMIN">
|
||||||
|
<meta-data android:name="android.app.corp_device_admin"
|
||||||
|
android:resource="@xml/corp_device_admin" />
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
36
samples/CorpApp/res/layout/corp_app_activity.xml
Normal file
36
samples/CorpApp/res/layout/corp_app_activity.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 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">
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical" android:padding="4dip"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/status_text"
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:paddingBottom="4dip"
|
||||||
|
android:text="@string/corp_app_status_waiting_text"/>
|
||||||
|
|
||||||
|
<Button android:id="@+id/set_button"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="@string/corp_app_set_button_text"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
30
samples/CorpApp/res/values/strings.xml
Normal file
30
samples/CorpApp/res/values/strings.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="corp_app_title_text">Corporate Demo App</string>
|
||||||
|
<string name="corp_app_set_button_text">Set Corp Global Proxy</string>
|
||||||
|
<string name="corp_app_status_success_text">Global Proxy successfully set</string>
|
||||||
|
<string name="corp_app_status_failed_text">Global Proxy could not be set.</string>
|
||||||
|
<string name="corp_app_status_waiting_text">Waiting to set Global Proxy...</string>
|
||||||
|
<string name="corp_app_proxy_name">proxy.corpapp.com:8080</string>
|
||||||
|
<string name="corp_app_proxy_excl_list">google.com,youtube.com</string>
|
||||||
|
<string name="corp_app_activity">Sample Corp App Activity</string>
|
||||||
|
<string name="corp_app_admin">Sample Corp App Device Admin</string>
|
||||||
|
<string name="corp_device_admin_description">Corporate device admin sample demo</string>
|
||||||
|
|
||||||
|
</resources>
|
||||||
24
samples/CorpApp/res/xml/corp_device_admin.xml
Normal file
24
samples/CorpApp/res/xml/corp_device_admin.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- BEGIN_INCLUDE(meta_data) -->
|
||||||
|
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<uses-policies>
|
||||||
|
<set-global-proxy />
|
||||||
|
</uses-policies>
|
||||||
|
</device-admin>
|
||||||
|
<!-- END_INCLUDE(meta_data) -->
|
||||||
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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.corpapp;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A minimal Globl Proxy-setting corp app application.
|
||||||
|
*/
|
||||||
|
public class CorpAppActivity extends Activity {
|
||||||
|
/**
|
||||||
|
* Called with the activity is first created.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Button mSetButton;
|
||||||
|
TextView mStatusText;
|
||||||
|
String mProxyName;
|
||||||
|
String mProxyExclList;
|
||||||
|
String mSuccess;
|
||||||
|
String mFailure;
|
||||||
|
|
||||||
|
DevicePolicyManager mDPM;
|
||||||
|
ActivityManager mAM;
|
||||||
|
ComponentName mCorpDeviceAdmin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
mCorpDeviceAdmin = new ComponentName(CorpAppActivity.this, CorpDeviceAdmin.class);
|
||||||
|
|
||||||
|
// Set the layout for this activity. You can find it
|
||||||
|
// in res/layout/corp_app_activity.xml
|
||||||
|
setContentView(R.layout.corp_app_activity);
|
||||||
|
|
||||||
|
mSetButton = (Button)findViewById(R.id.set_button);
|
||||||
|
mSetButton.setOnClickListener(mSetListener);
|
||||||
|
mStatusText = (Button)findViewById(R.id.status_text);
|
||||||
|
|
||||||
|
boolean active = mDPM.isAdminActive(mCorpDeviceAdmin);
|
||||||
|
mSetButton.setEnabled(active);
|
||||||
|
mProxyName = getResources().getString(R.string.corp_app_proxy_name);
|
||||||
|
mProxyExclList = getResources().getString(R.string.corp_app_proxy_excl_list);
|
||||||
|
mSuccess = getResources().getString(R.string.corp_app_status_success_text);
|
||||||
|
mFailure = getResources().getString(R.string.corp_app_status_failed_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnClickListener mSetListener = new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
String[] proxyComponents = mProxyName.split(":");
|
||||||
|
if (proxyComponents.length != 2) {
|
||||||
|
Toast.makeText(CorpAppActivity.this, "Wrong proxy specification.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Proxy instProxy = new Proxy(Proxy.Type.HTTP,
|
||||||
|
new InetSocketAddress(proxyComponents[0],
|
||||||
|
Integer.parseInt(proxyComponents[1])));
|
||||||
|
String[] listDoms = mProxyExclList.split(",");
|
||||||
|
if (listDoms.length == 0) {
|
||||||
|
Toast.makeText(CorpAppActivity.this, "Wrong exclusion list format.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
List<String> exclList = Arrays.asList(listDoms);
|
||||||
|
boolean active = mDPM.isAdminActive(mCorpDeviceAdmin);
|
||||||
|
if (active) {
|
||||||
|
mDPM.setGlobalProxy(mCorpDeviceAdmin, instProxy, exclList);
|
||||||
|
ComponentName proxyAdmin = mDPM.getGlobalProxyAdmin();
|
||||||
|
if ((proxyAdmin != null) && (proxyAdmin.equals(mCorpDeviceAdmin))) {
|
||||||
|
Toast.makeText(CorpAppActivity.this, "Global Proxy set by device admin.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
mStatusText.setText(mSuccess);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(CorpAppActivity.this, "Failed to set Global Proxy.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
mStatusText.setText(mFailure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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.corpapp;
|
||||||
|
|
||||||
|
import android.app.admin.DeviceAdminReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class CorpDeviceAdmin extends DeviceAdminReceiver {
|
||||||
|
|
||||||
|
static SharedPreferences getSamplePreferences(Context context) {
|
||||||
|
return context.getSharedPreferences(DeviceAdminReceiver.class.getName(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void showToast(Context context, CharSequence msg) {
|
||||||
|
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnabled(Context context, Intent intent) {
|
||||||
|
showToast(context, "Sample Corp Device Admin: enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence onDisableRequested(Context context, Intent intent) {
|
||||||
|
return "Sample Corp Device Admin: disable requested";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisabled(Context context, Intent intent) {
|
||||||
|
showToast(context, "Sample Corp Device Admin: disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasswordChanged(Context context, Intent intent) {
|
||||||
|
showToast(context, "Sample Corp Device Admin: pw changed");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasswordFailed(Context context, Intent intent) {
|
||||||
|
showToast(context, "Sample Corp Device Admin: pw failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasswordSucceeded(Context context, Intent intent) {
|
||||||
|
showToast(context, "Sample Corp Device Admin: pw succeeded");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user