1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import android.app.ActivityManager; 18 import android.content.Context; 19 import android.content.pm.IPackageDataObserver; 20 21 public class ActivityManagerCompat { 22 private final ActivityManager mActivityManager; 23 24 public interface PackageDataObserver { onRemoveCompleted(String packageName, boolean succeeded)25 void onRemoveCompleted(String packageName, boolean succeeded); 26 } 27 ActivityManagerCompat(Context context)28 public ActivityManagerCompat(Context context) { 29 mActivityManager = (ActivityManager) context.getSystemService( 30 Context.ACTIVITY_SERVICE); 31 } 32 isLowRamDeviceStatic()33 public static boolean isLowRamDeviceStatic() { 34 return ActivityManager.isLowRamDeviceStatic(); 35 } 36 switchUser(int userid)37 public boolean switchUser(int userid) { 38 return mActivityManager.switchUser(userid); 39 } 40 getService()41 public static Object getService() { 42 return ActivityManager.getService(); 43 } 44 clearApplicationUserData(String packageName, PackageDataObserver observer)45 public boolean clearApplicationUserData(String packageName, PackageDataObserver observer) { 46 return mActivityManager.clearApplicationUserData(packageName, 47 new IPackageDataObserver.Stub() { 48 public void onRemoveCompleted(final String packageName, 49 final boolean succeeded) { 50 observer.onRemoveCompleted(packageName, succeeded); 51 } 52 }); 53 } 54 } 55