|
17 | 17 | import android.content.Context;
|
18 | 18 | import android.content.Intent;
|
19 | 19 | import android.content.IntentFilter;
|
20 |
| -import android.content.pm.ApplicationInfo; |
21 |
| -import android.content.pm.PackageManager; |
22 | 20 | import android.os.Build;
|
23 | 21 | import android.os.Bundle;
|
24 | 22 | import android.util.Log;
|
@@ -72,40 +70,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
72 | 70 | return inflater.inflate(R.layout.basic_managed_profile_fragment, container, false);
|
73 | 71 | }
|
74 | 72 |
|
75 |
| - |
76 |
| - /** |
77 |
| - * Checks if the application is available in this profile. |
78 |
| - * |
79 |
| - * @param packageName The package name |
80 |
| - * @return True if the application is available in this profile. |
81 |
| - */ |
82 |
| - private boolean isApplicationEnabled(String packageName) { |
83 |
| - Activity activity = getActivity(); |
84 |
| - PackageManager packageManager = activity.getPackageManager(); |
85 |
| - try { |
86 |
| - int packageFlags; |
87 |
| - if (Build.VERSION.SDK_INT < 24) { |
88 |
| - //noinspection deprecation |
89 |
| - packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; |
90 |
| - } else { |
91 |
| - packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; |
92 |
| - } |
93 |
| - ApplicationInfo applicationInfo = |
94 |
| - packageManager.getApplicationInfo(packageName, packageFlags); |
95 |
| - // Return false if the app is not installed in this profile |
96 |
| - if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) { |
97 |
| - return false; |
98 |
| - } |
99 |
| - // Check if the app is not hidden in this profile |
100 |
| - DevicePolicyManager devicePolicyManager = |
101 |
| - (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); |
102 |
| - return !devicePolicyManager.isApplicationHidden( |
103 |
| - BasicDeviceAdminReceiver.getComponentName(activity), packageName); |
104 |
| - } catch (PackageManager.NameNotFoundException exception) { |
105 |
| - return false; |
106 |
| - } |
107 |
| - } |
108 |
| - |
109 | 73 | @Override
|
110 | 74 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
111 | 75 | // Bind event listeners and initial states
|
@@ -156,58 +120,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
156 | 120 | }
|
157 | 121 | }
|
158 | 122 |
|
159 |
| - /** |
160 |
| - * Enables or disables the specified app in this profile. |
161 |
| - * |
162 |
| - * @param packageName The package name of the target app. |
163 |
| - * @param enabled Pass true to enable the app. |
164 |
| - */ |
165 |
| - |
166 |
| - private void setAppEnabled(String packageName, boolean enabled) { |
167 |
| - Activity activity = getActivity(); |
168 |
| - if (null == activity) { |
169 |
| - return; |
170 |
| - } |
171 |
| - PackageManager packageManager = activity.getPackageManager(); |
172 |
| - DevicePolicyManager devicePolicyManager = |
173 |
| - (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE); |
174 |
| - |
175 |
| - try { |
176 |
| - int packageFlags; |
177 |
| - if (Build.VERSION.SDK_INT < 24) { |
178 |
| - //noinspection deprecation |
179 |
| - packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; |
180 |
| - } else { |
181 |
| - packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; |
182 |
| - } |
183 |
| - ApplicationInfo applicationInfo = |
184 |
| - packageManager.getApplicationInfo(packageName, packageFlags); |
185 |
| - // Here, we check the ApplicationInfo of the target app, and see if the flags have |
186 |
| - // ApplicationInfo.FLAG_INSTALLED turned on using bitwise operation. |
187 |
| - if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) { |
188 |
| - // If the app is not installed in this profile, we can enable it by |
189 |
| - // DPM.enableSystemApp |
190 |
| - if (enabled) { |
191 |
| - devicePolicyManager.enableSystemApp( |
192 |
| - BasicDeviceAdminReceiver.getComponentName(activity), packageName); |
193 |
| - } else { |
194 |
| - // But we cannot disable the app since it is already disabled |
195 |
| - Log.e(TAG, "Cannot disable this app: " + packageName); |
196 |
| - return; |
197 |
| - } |
198 |
| - } else { |
199 |
| - // If the app is already installed, we can enable or disable it by |
200 |
| - // DPM.setApplicationHidden |
201 |
| - devicePolicyManager.setApplicationHidden( |
202 |
| - BasicDeviceAdminReceiver.getComponentName(activity), packageName, !enabled); |
203 |
| - } |
204 |
| - Toast.makeText(activity, enabled ? R.string.enabled : R.string.disabled, |
205 |
| - Toast.LENGTH_SHORT).show(); |
206 |
| - } catch (PackageManager.NameNotFoundException exception) { |
207 |
| - Log.e(TAG, "The app cannot be found: " + packageName, exception); |
208 |
| - } |
209 |
| - } |
210 |
| - |
211 | 123 | /**
|
212 | 124 | * Enables forwarding of share intent between private account and managed profile.
|
213 | 125 | */
|
|
0 commit comments