-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge /usr/local/google/home/ascull/projects/ub-testdpc-oc-release/ve…
…ndor/unbundled_google/packages/TestDPC into new-version
- Loading branch information
Showing
13 changed files
with
213 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/afwsamples/testdpc/policy/PersistentDeviceOwnerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.afwsamples.testdpc.policy; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Fragment; | ||
import android.app.admin.DevicePolicyManager; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import com.afwsamples.testdpc.DeviceAdminReceiver; | ||
import com.afwsamples.testdpc.R; | ||
import com.afwsamples.testdpc.common.Util; | ||
|
||
/** | ||
* Allows the user to set a test persistent device owner state. | ||
* | ||
* <p>For manual testing of forced re-enrollment. | ||
* | ||
* <p>If there is a non-empty peristent device owner state, it will survive the next factory reset, | ||
* TestDPC will be re-installed automatically as device owner and the state will be passed to it | ||
* during the initial device setup. | ||
*/ | ||
public class PersistentDeviceOwnerFragment extends Fragment implements View.OnClickListener { | ||
|
||
private DevicePolicyManager mDpm; | ||
private ComponentName mAdminComponent; | ||
private EditText mStateEdit; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getActivity().getActionBar().setTitle(R.string.persistent_device_owner); | ||
mDpm = (DevicePolicyManager) getActivity().getSystemService( | ||
Context.DEVICE_POLICY_SERVICE); | ||
mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity()); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View root = inflater.inflate(R.layout.persistent_device_owner_fragment, container, false); | ||
root.findViewById(R.id.clear_persistent_device_owner_button).setOnClickListener(this); | ||
root.findViewById(R.id.set_persistent_device_owner_button).setOnClickListener(this); | ||
mStateEdit = (EditText) root.findViewById(R.id.persistent_device_owner_state_edit); | ||
return root; | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
String message = null; | ||
switch (view.getId()) { | ||
case R.id.clear_persistent_device_owner_button: | ||
mStateEdit.getText().clear(); | ||
Util.setPersistentDoStateWithApplicationRestriction( | ||
getActivity(), mDpm, mAdminComponent, null); | ||
break; | ||
case R.id.set_persistent_device_owner_button: | ||
Util.setPersistentDoStateWithApplicationRestriction( | ||
getActivity(), mDpm, mAdminComponent, mStateEdit.getText().toString()); | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
String state = Util.getPersistentDoStateFromApplicationRestriction(mDpm, mAdminComponent); | ||
mStateEdit.setText(state == null ? "" : state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/res/layout/persistent_device_owner_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2017 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. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="10dp" | ||
android:orientation="vertical"> | ||
<EditText android:id="@+id/persistent_device_owner_state_edit" | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" | ||
android:lines="5" | ||
android:layout_gravity="center" | ||
android:hint="@string/persistent_device_owner_state_hint"/> | ||
<LinearLayout | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_gravity="center" | ||
android:orientation="horizontal"> | ||
<Button android:id="@+id/clear_persistent_device_owner_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/clear_persistent_device_owner_label" | ||
android:layout_margin="8dp" | ||
android:visibility="visible"/> | ||
<Button android:id="@+id/set_persistent_device_owner_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/set_persistent_device_owner_label" | ||
android:layout_margin="8dp" | ||
android:visibility="visible"/> | ||
</LinearLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.