use of android.annotation.SystemApi in project android_frameworks_base by crdroidandroid.
the class RecoverySystem method installPackage.
/**
* If the package hasn't been processed (i.e. uncrypt'd), set up
* UNCRYPT_PACKAGE_FILE and delete BLOCK_MAP_FILE to trigger uncrypt during the
* reboot.
*
* @param context the Context to use
* @param packageFile the update package to install. Must be on a
* partition mountable by recovery.
* @param processed if the package has been processed (uncrypt'd).
*
* @throws IOException if writing the recovery command file fails, or if
* the reboot itself fails.
*
* @hide
*/
@SystemApi
public static void installPackage(Context context, File packageFile, boolean processed) throws IOException {
synchronized (sRequestLock) {
LOG_FILE.delete();
// Must delete the file in case it was created by system server.
UNCRYPT_PACKAGE_FILE.delete();
String filename = packageFile.getCanonicalPath();
Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!");
// If the package name ends with "_s.zip", it's a security update.
boolean securityUpdate = filename.endsWith("_s.zip");
// been done in 'processed' parameter.
if (filename.startsWith("/data/")) {
if (processed) {
if (!BLOCK_MAP_FILE.exists()) {
Log.e(TAG, "Package claimed to have been processed but failed to find " + "the block map file.");
throw new IOException("Failed to find block map file");
}
} else {
FileWriter uncryptFile = new FileWriter(UNCRYPT_PACKAGE_FILE);
try {
uncryptFile.write(filename + "\n");
} finally {
uncryptFile.close();
}
// by system server.
if (!UNCRYPT_PACKAGE_FILE.setReadable(true, false) || !UNCRYPT_PACKAGE_FILE.setWritable(true, false)) {
Log.e(TAG, "Error setting permission for " + UNCRYPT_PACKAGE_FILE);
}
BLOCK_MAP_FILE.delete();
}
// If the package is on the /data partition, use the block map
// file as the package name instead.
filename = "@/cache/recovery/block.map";
}
final String filenameArg = "--update_package=" + filename + "\n";
final String localeArg = "--locale=" + Locale.getDefault().toString() + "\n";
final String securityArg = "--security\n";
String command = filenameArg + localeArg;
if (securityUpdate) {
command += securityArg;
}
RecoverySystem rs = (RecoverySystem) context.getSystemService(Context.RECOVERY_SERVICE);
if (!rs.setupBcb(command)) {
throw new IOException("Setup BCB failed");
}
// Having set up the BCB (bootloader control block), go ahead and reboot
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.reboot(PowerManager.REBOOT_RECOVERY_UPDATE);
throw new IOException("Reboot failed (no permissions?)");
}
}
use of android.annotation.SystemApi in project android_frameworks_base by crdroidandroid.
the class DevicePolicyManager method getDeviceOwner.
/**
* Returns the device owner package name, only if it's running on the calling user.
*
* <p>Bundled components should use {@code getDeviceOwnerComponentOnCallingUser()} for clarity.
*
* @hide
*/
@SystemApi
public String getDeviceOwner() {
throwIfParentInstance("getDeviceOwner");
final ComponentName name = getDeviceOwnerComponentOnCallingUser();
return name != null ? name.getPackageName() : null;
}
use of android.annotation.SystemApi in project android_frameworks_base by crdroidandroid.
the class TelephonyManager method setDataEnabled.
/** @hide */
@SystemApi
public void setDataEnabled(int subId, boolean enable) {
try {
Log.d(TAG, "setDataEnabled: enabled=" + enable);
AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
if (enable) {
if (appOps.noteOp(AppOpsManager.OP_DATA_CONNECT_CHANGE) != AppOpsManager.MODE_ALLOWED) {
Log.w(TAG, "Permission denied by user.");
return;
}
}
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.setDataEnabled(subId, enable);
} catch (RemoteException e) {
Log.e(TAG, "Error calling setDataEnabled", e);
} catch (NullPointerException npe) {
Log.e(TAG, "Error calling setDataEnabled", npe);
}
}
use of android.annotation.SystemApi in project android_frameworks_base by crdroidandroid.
the class TelecomManager method dumpAnalytics.
/**
* Dumps telecom analytics for uploading.
*
* @return
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.DUMP)
public TelecomAnalytics dumpAnalytics() {
ITelecomService service = getTelecomService();
TelecomAnalytics result = null;
if (service != null) {
try {
result = service.dumpCallAnalytics();
} catch (RemoteException e) {
Log.e(TAG, "Error dumping call analytics", e);
}
}
return result;
}
use of android.annotation.SystemApi in project robolectric by robolectric.
the class ShadowTelecomManager method createLaunchEmergencyDialerIntent.
@Implementation(minSdk = R)
@SystemApi
protected Intent createLaunchEmergencyDialerIntent(String number) {
// copy of logic from TelecomManager service
Context context = ReflectionHelpers.getField(realObject, "mContext");
// use reflection to get resource id since it can vary based on SDK version, and compiler will
// inline the value if used explicitly
int configEmergencyDialerPackageId = ReflectionHelpers.getStaticField(com.android.internal.R.string.class, "config_emergency_dialer_package");
String packageName = context.getString(configEmergencyDialerPackageId);
Intent intent = new Intent(Intent.ACTION_DIAL_EMERGENCY).setPackage(packageName);
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, 0);
if (resolveInfo == null) {
// No matching activity from config, fallback to default platform implementation
intent.setPackage(null);
}
if (!TextUtils.isEmpty(number) && TextUtils.isDigitsOnly(number)) {
intent.setData(Uri.parse("tel:" + number));
}
return intent;
}
Aggregations