Search in sources :

Example 91 with SystemApi

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?)");
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) SystemApi(android.annotation.SystemApi)

Example 92 with SystemApi

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;
}
Also used : ComponentName(android.content.ComponentName) SystemApi(android.annotation.SystemApi)

Example 93 with SystemApi

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);
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony) SystemApi(android.annotation.SystemApi)

Example 94 with SystemApi

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;
}
Also used : ITelecomService(com.android.internal.telecom.ITelecomService) RemoteException(android.os.RemoteException) SystemApi(android.annotation.SystemApi) RequiresPermission(android.annotation.RequiresPermission)

Example 95 with SystemApi

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;
}
Also used : Context(android.content.Context) ResolveInfo(android.content.pm.ResolveInfo) R(android.os.Build.VERSION_CODES.R) Intent(android.content.Intent) SystemApi(android.annotation.SystemApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

SystemApi (android.annotation.SystemApi)96 Bundle (android.os.Bundle)36 RemoteException (android.os.RemoteException)33 INotificationManager (android.app.INotificationManager)10 RequiresPermission (android.annotation.RequiresPermission)6 ComponentName (android.content.ComponentName)6 NonNull (android.annotation.NonNull)5 Notification (android.app.Notification)5 AudioFormat (android.media.AudioFormat)5 AudioRecord (android.media.AudioRecord)5 AudioTrack (android.media.AudioTrack)5 Parcel (android.os.Parcel)5 TextPaint (android.text.TextPaint)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ITelecomService (com.android.internal.telecom.ITelecomService)4 ICarrierConfigLoader (com.android.internal.telephony.ICarrierConfigLoader)4 ITelephony (com.android.internal.telephony.ITelephony)4 Implementation (org.robolectric.annotation.Implementation)3