-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snap for 6833135 from 7905bce6ca7f576a4feb8b3c01986a3b55667f6e to ub-…
…testdpc-rvc-release Change-Id: I1ffc878b9028a1e368fff590685f700bffd4a00f
- Loading branch information
Showing
17 changed files
with
319 additions
and
204 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
111 changes: 111 additions & 0 deletions
111
app/src/main/java/com/afwsamples/testdpc/CrossProfileAppsWhitelistFragment.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,111 @@ | ||
/* | ||
* Copyright (C) 2020 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.afwsamples.testdpc; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Fragment; | ||
import android.app.admin.DevicePolicyManager; | ||
import android.content.ComponentName; | ||
import android.os.Build.VERSION_CODES; | ||
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 android.widget.TextView; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* This fragment provides the ability to whitelist cross profile packages | ||
* | ||
* <p>APIs exercised: | ||
* <ul> | ||
* <li> {@link DevicePolicyManager#setCrossProfilePackages(ComponentName, Set)} </li> | ||
* <li> {@link DevicePolicyManager#getCrossProfilePackages(ComponentName)} </li> | ||
* </ul> | ||
*/ | ||
@TargetApi(VERSION_CODES.R) | ||
public class CrossProfileAppsWhitelistFragment extends Fragment { | ||
private static final String DELIMITER = "\n"; | ||
|
||
private View mInflatedView; | ||
private EditText mAppNameEditText; | ||
private Button mResetButton; | ||
private Button mAddButton; | ||
private Button mRemoveButton; | ||
private TextView mAppsList; | ||
|
||
private DevicePolicyManager mDevicePolicyManager; | ||
private ComponentName mAdminComponent; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
mDevicePolicyManager = getActivity().getSystemService(DevicePolicyManager.class); | ||
mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity()); | ||
mInflatedView = inflater.inflate( | ||
R.layout.cross_profile_apps_whitelist, container, false); | ||
|
||
mAppNameEditText = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_input); | ||
mResetButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_reset_button); | ||
mAddButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_add_button); | ||
mRemoveButton = mInflatedView.findViewById(R.id.cross_profile_app_whitelist_remove_button); | ||
mAppsList = mInflatedView.findViewById(R.id.cross_profile_app_list); | ||
|
||
setOnClickListeners(); | ||
updateCrossProfileAppsList(); | ||
|
||
return mInflatedView; | ||
} | ||
|
||
private void setOnClickListeners() { | ||
mResetButton.setOnClickListener(view -> resetApps()); | ||
mAddButton.setOnClickListener( | ||
view -> addApp(mAppNameEditText.getText().toString().toLowerCase().trim())); | ||
mRemoveButton.setOnClickListener( | ||
view -> removeApp(mAppNameEditText.getText().toString().toLowerCase().trim())); | ||
} | ||
|
||
private void resetApps() { | ||
mDevicePolicyManager.setCrossProfilePackages(mAdminComponent, Collections.emptySet()); | ||
updateCrossProfileAppsList(); | ||
} | ||
|
||
private void addApp(String app) { | ||
Set<String> currentApps = mDevicePolicyManager.getCrossProfilePackages(mAdminComponent); | ||
currentApps.add(app); | ||
mDevicePolicyManager.setCrossProfilePackages(mAdminComponent, currentApps); | ||
updateCrossProfileAppsList(); | ||
} | ||
|
||
private void removeApp(String app) { | ||
Set<String> currentApps = mDevicePolicyManager.getCrossProfilePackages(mAdminComponent); | ||
currentApps.remove(app); | ||
mDevicePolicyManager.setCrossProfilePackages(mAdminComponent, currentApps); | ||
updateCrossProfileAppsList(); | ||
} | ||
|
||
private void updateCrossProfileAppsList(){ | ||
Set<String> currentApps = mDevicePolicyManager.getCrossProfilePackages(mAdminComponent); | ||
if (currentApps.isEmpty()) { | ||
mAppsList.setText(R.string.cross_profile_apps_no_whitelisted_apps); | ||
} else { | ||
mAppsList.setText(String.join(DELIMITER, currentApps)); | ||
} | ||
} | ||
} |
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: 0 additions & 77 deletions
77
app/src/main/java/com/afwsamples/testdpc/policy/PersistentDeviceOwnerFragment.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.