Java Code Examples for android.os.Build#IS_DEBUGGABLE

The following examples show how to use android.os.Build#IS_DEBUGGABLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalSettingsToPropertiesMapper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void setProperty(String key, String value) {
    // Check if need to clear the property
    if (value == null) {
        // It's impossible to remove system property, therefore we check previous value to
        // avoid setting an empty string if the property wasn't set.
        if (TextUtils.isEmpty(systemPropertiesGet(key))) {
            return;
        }
        value = "";
    }
    try {
        systemPropertiesSet(key, value);
    } catch (Exception e) {
        // Failure to set a property can be caused by SELinux denial. This usually indicates
        // that the property wasn't whitelisted in sepolicy.
        // No need to report it on all user devices, only on debug builds.
        if (Build.IS_DEBUGGABLE) {
            Slog.wtf(TAG, "Unable to set property " + key + " value '" + value + "'", e);
        } else {
            Slog.e(TAG, "Unable to set property " + key + " value '" + value + "'", e);
        }
    }
}
 
Example 2
Source File: SettingsState.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public SettingsState(Context context, Object lock, File file, int key,
        int maxBytesPerAppPackage, Looper looper) {
    // It is important that we use the same lock as the settings provider
    // to ensure multiple mutations on this state are atomicaly persisted
    // as the async persistence should be blocked while we make changes.
    mContext = context;
    mLock = lock;
    mStatePersistFile = file;
    mKey = key;
    mHandler = new MyHandler(looper);
    if (maxBytesPerAppPackage == MAX_BYTES_PER_APP_PACKAGE_LIMITED) {
        mMaxBytesPerAppPackage = maxBytesPerAppPackage;
        mPackageToMemoryUsage = new ArrayMap<>();
    } else {
        mMaxBytesPerAppPackage = maxBytesPerAppPackage;
        mPackageToMemoryUsage = null;
    }

    mHistoricalOperations = Build.IS_DEBUGGABLE
            ? new ArrayList<>(HISTORICAL_OPERATION_COUNT) : null;

    synchronized (mLock) {
        readStateSyncLocked();
    }
}
 
Example 3
Source File: AccessibilityInteractionClient.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the the result of an async request that returns {@link AccessibilityNodeInfo}s.
 *
 * @param interactionId The interaction id to match the result with the request.
 * @return The result {@link AccessibilityNodeInfo}s.
 */
private List<AccessibilityNodeInfo> getFindAccessibilityNodeInfosResultAndClear(
            int interactionId) {
    synchronized (mInstanceLock) {
        final boolean success = waitForResultTimedLocked(interactionId);
        final List<AccessibilityNodeInfo> result;
        if (success) {
            result = mFindAccessibilityNodeInfosResult;
        } else {
            result = Collections.emptyList();
        }
        clearResultLocked();
        if (Build.IS_DEBUGGABLE && CHECK_INTEGRITY) {
            checkFindAccessibilityNodeInfoResultIntegrity(result);
        }
        return result;
    }
}
 
Example 4
Source File: DreamManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onBootPhase(int phase) {
    if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
        if (Build.IS_DEBUGGABLE) {
            SystemProperties.addChangeCallback(mSystemPropertiesChanged);
        }
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                writePulseGestureEnabled();
                synchronized (mLock) {
                    stopDreamLocked(false /*immediate*/);
                }
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP), false,
                mDozeEnabledObserver, UserHandle.USER_ALL);
        writePulseGestureEnabled();
    }
}
 
Example 5
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static int getMaxManagedProfiles() {
    // Allow overriding max managed profiles on debuggable builds for testing
    // of multiple profiles.
    if (!Build.IS_DEBUGGABLE) {
        return MAX_MANAGED_PROFILES;
    } else {
        return SystemProperties.getInt("persist.sys.max_profiles",
                MAX_MANAGED_PROFILES);
    }
}
 
Example 6
Source File: NativeDaemonConnector.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private LocalSocketAddress determineSocketAddress() {
    // If we're testing, set up a socket in a namespace that's accessible to test code.
    // In order to ensure that unprivileged apps aren't able to impersonate native daemons on
    // production devices, even if said native daemons ill-advisedly pick a socket name that
    // starts with __test__, only allow this on debug builds.
    if (mSocket.startsWith("__test__") && Build.IS_DEBUGGABLE) {
        return new LocalSocketAddress(mSocket);
    } else {
        return new LocalSocketAddress(mSocket, LocalSocketAddress.Namespace.RESERVED);
    }
}
 
Example 7
Source File: Watchdog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static OpenFdMonitor create() {
    // Only run the FD monitor on debuggable builds (such as userdebug and eng builds).
    if (!Build.IS_DEBUGGABLE) {
        return null;
    }

    // Don't run the FD monitor on builds that have a global ANR trace file. We're using
    // the ANR trace directory as a quick hack in order to get these traces in bugreports
    // and we wouldn't want to overwrite something important.
    final String dumpDirStr = SystemProperties.get("dalvik.vm.stack-trace-dir", "");
    if (dumpDirStr.isEmpty()) {
        return null;
    }

    final StructRlimit rlimit;
    try {
        rlimit = android.system.Os.getrlimit(OsConstants.RLIMIT_NOFILE);
    } catch (ErrnoException errno) {
        Slog.w(TAG, "Error thrown from getrlimit(RLIMIT_NOFILE)", errno);
        return null;
    }

    // The assumption we're making here is that FD numbers are allocated (more or less)
    // sequentially, which is currently (and historically) true since open is currently
    // specified to always return the lowest-numbered non-open file descriptor for the
    // current process.
    //
    // We do this to avoid having to enumerate the contents of /proc/self/fd in order to
    // count the number of descriptors open in the process.
    final File fdThreshold = new File("/proc/self/fd/" + (rlimit.rlim_cur - FD_HIGH_WATER_MARK));
    return new OpenFdMonitor(new File(dumpDirStr), fdThreshold);
}
 
Example 8
Source File: DexManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Generates package related log if the package has code stored in unexpected way.
 */
public static void maybeLogUnexpectedPackageDetails(PackageParser.Package pkg) {
    if (!Build.IS_DEBUGGABLE) {
        return;
    }

    if (pkg.isPrivileged() && isPackageSelectedToRunOob(pkg.packageName)) {
        logIfPackageHasUncompressedCode(pkg);
    }
}
 
Example 9
Source File: SyncLogger.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @return the singleton instance.
 */
public static synchronized SyncLogger getInstance() {
    if (sInstance == null) {
        final boolean enable =
                Build.IS_DEBUGGABLE
                || "1".equals(SystemProperties.get("debug.synclog"))
                || Log.isLoggable(TAG, Log.VERBOSE);
        if (enable) {
            sInstance = new RotatingFileLogger();
        } else {
            sInstance = new SyncLogger();
        }
    }
    return sInstance;
}
 
Example 10
Source File: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
/** @hide */
public static boolean isLowRamDeviceStatic() {
    return RoSystemProperties.CONFIG_LOW_RAM ||
            (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
}
 
Example 11
Source File: SQLiteQueryBuilder.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a query by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to query on
 * @param projectionIn A list of which columns to return. Passing
 *   null will return all columns, which is discouraged to prevent
 *   reading data from storage that isn't going to be used.
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @param groupBy A filter declaring how to group rows, formatted
 *   as an SQL GROUP BY clause (excluding the GROUP BY
 *   itself). Passing null will cause the rows to not be grouped.
 * @param having A filter declare which row groups to include in
 *   the cursor, if row grouping is being used, formatted as an
 *   SQL HAVING clause (excluding the HAVING itself).  Passing
 *   null will cause all row groups to be included, and is
 *   required when row grouping is not being used.
 * @param sortOrder How to order the rows, formatted as an SQL
 *   ORDER BY clause (excluding the ORDER BY itself). Passing null
 *   will use the default sort order, which may be unordered.
 * @param limit Limits the number of rows returned by the query,
 *   formatted as LIMIT clause. Passing null denotes no LIMIT clause.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * If the operation is canceled, then {@link OperationCanceledException} will be thrown
 * when the query is executed.
 * @return a cursor over the result set
 * @see android.content.ContentResolver#query(android.net.Uri, String[],
 *      String, String[], String)
 */
public Cursor query(SQLiteDatabase db, String[] projectionIn,
        String selection, String[] selectionArgs, String groupBy,
        String having, String sortOrder, String limit, CancellationSignal cancellationSignal) {
    if (mTables == null) {
        return null;
    }

    final String sql;
    final String unwrappedSql = buildQuery(
            projectionIn, selection, groupBy, having,
            sortOrder, limit);

    if (mStrict && selection != null && selection.length() > 0) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, cancellationSignal); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildQuery(projectionIn, wrap(selection), groupBy,
                having, sortOrder, limit);
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    final String[] sqlArgs = selectionArgs;
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.rawQueryWithFactory(
            mFactory, sql, sqlArgs,
            SQLiteDatabase.findEditTable(mTables),
            cancellationSignal); // will throw if query is invalid
}
 
Example 12
Source File: SQLiteQueryBuilder.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Perform an update by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to update on
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @return the number of rows updated
 * @hide
 */
public int update(@NonNull SQLiteDatabase db, @NonNull ContentValues values,
        @Nullable String selection, @Nullable String[] selectionArgs) {
    Objects.requireNonNull(mTables, "No tables defined");
    Objects.requireNonNull(db, "No database defined");
    Objects.requireNonNull(values, "No values defined");

    final String sql;
    final String unwrappedSql = buildUpdate(values, selection);

    if (mStrict) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, null); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildUpdate(values, wrap(selection));
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    if (selectionArgs == null) {
        selectionArgs = EmptyArray.STRING;
    }
    final String[] rawKeys = values.keySet().toArray(EmptyArray.STRING);
    final int valuesLength = rawKeys.length;
    final Object[] sqlArgs = new Object[valuesLength + selectionArgs.length];
    for (int i = 0; i < sqlArgs.length; i++) {
        if (i < valuesLength) {
            sqlArgs[i] = values.get(rawKeys[i]);
        } else {
            sqlArgs[i] = selectionArgs[i - valuesLength];
        }
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.executeSql(sql, sqlArgs);
}
 
Example 13
Source File: SQLiteQueryBuilder.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a delete by combining all current settings and the
 * information passed into this method.
 *
 * @param db the database to delete on
 * @param selection A filter declaring which rows to return,
 *   formatted as an SQL WHERE clause (excluding the WHERE
 *   itself). Passing null will return all rows for the given URL.
 * @param selectionArgs You may include ?s in selection, which
 *   will be replaced by the values from selectionArgs, in order
 *   that they appear in the selection. The values will be bound
 *   as Strings.
 * @return the number of rows deleted
 * @hide
 */
public int delete(@NonNull SQLiteDatabase db, @Nullable String selection,
        @Nullable String[] selectionArgs) {
    Objects.requireNonNull(mTables, "No tables defined");
    Objects.requireNonNull(db, "No database defined");

    final String sql;
    final String unwrappedSql = buildDelete(selection);

    if (mStrict) {
        // Validate the user-supplied selection to detect syntactic anomalies
        // in the selection string that could indicate a SQL injection attempt.
        // The idea is to ensure that the selection clause is a valid SQL expression
        // by compiling it twice: once wrapped in parentheses and once as
        // originally specified. An attacker cannot create an expression that
        // would escape the SQL expression while maintaining balanced parentheses
        // in both the wrapped and original forms.

        // NOTE: The ordering of the below operations is important; we must
        // execute the wrapped query to ensure the untrusted clause has been
        // fully isolated.

        // Validate the unwrapped query
        db.validateSql(unwrappedSql, null); // will throw if query is invalid

        // Execute wrapped query for extra protection
        final String wrappedSql = buildDelete(wrap(selection));
        sql = wrappedSql;
    } else {
        // Execute unwrapped query
        sql = unwrappedSql;
    }

    final String[] sqlArgs = selectionArgs;
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        if (Build.IS_DEBUGGABLE) {
            Log.d(TAG, sql + " with args " + Arrays.toString(sqlArgs));
        } else {
            Log.d(TAG, sql);
        }
    }
    return db.executeSql(sql, sqlArgs);
}
 
Example 14
Source File: ActivityManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** @hide */
public static boolean isLowRamDeviceStatic() {
    return RoSystemProperties.CONFIG_LOW_RAM ||
            (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
}
 
Example 15
Source File: IpSecAlgorithm.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isUnsafeBuild() {
    return Build.IS_DEBUGGABLE && Build.IS_ENG;
}
 
Example 16
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
private static boolean isCallerSystemOrShellOrRootOnDebuggableBuild() {
    final int appId = UserHandle.getAppId(Binder.getCallingUid());
    return appId == SYSTEM_UID || (Build.IS_DEBUGGABLE
            && (appId == SHELL_UID || appId == ROOT_UID));
}
 
Example 17
Source File: SystemImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean systemIsDebuggable() {
    return Build.IS_DEBUGGABLE;
}