Search in sources :

Example 36 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class BatteryService method logOutlierLocked.

private void logOutlierLocked(long duration) {
    ContentResolver cr = mContext.getContentResolver();
    String dischargeThresholdString = Settings.Global.getString(cr, Settings.Global.BATTERY_DISCHARGE_THRESHOLD);
    String durationThresholdString = Settings.Global.getString(cr, Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD);
    if (dischargeThresholdString != null && durationThresholdString != null) {
        try {
            long durationThreshold = Long.parseLong(durationThresholdString);
            int dischargeThreshold = Integer.parseInt(dischargeThresholdString);
            if (duration <= durationThreshold && mDischargeStartLevel - mBatteryProps.batteryLevel >= dischargeThreshold) {
                // If the discharge cycle is bad enough we want to know about it.
                logBatteryStatsLocked();
            }
            if (DEBUG)
                Slog.v(TAG, "duration threshold: " + durationThreshold + " discharge threshold: " + dischargeThreshold);
            if (DEBUG)
                Slog.v(TAG, "duration: " + duration + " discharge: " + (mDischargeStartLevel - mBatteryProps.batteryLevel));
        } catch (NumberFormatException e) {
            Slog.e(TAG, "Invalid DischargeThresholds GService string: " + durationThresholdString + " or " + dischargeThresholdString);
        }
    }
}
Also used : ContentResolver(android.content.ContentResolver)

Example 37 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class NetworkScoreService method refreshRecommendationRequestTimeoutMs.

@VisibleForTesting
public void refreshRecommendationRequestTimeoutMs() {
    final ContentResolver cr = mContext.getContentResolver();
    long timeoutMs = Settings.Global.getLong(cr, Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS, -1L);
    if (timeoutMs < 0) {
        timeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
    }
    if (DBG)
        Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
    mRecommendationRequestTimeoutMs = timeoutMs;
    mReqRecommendationCallerRef.set(new RequestRecommendationCaller(timeoutMs));
}
Also used : ContentResolver(android.content.ContentResolver) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 38 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class TextKeyListener method release.

public void release() {
    if (mResolver != null) {
        final ContentResolver contentResolver = mResolver.get();
        if (contentResolver != null) {
            contentResolver.unregisterContentObserver(mObserver);
            mResolver.clear();
        }
        mObserver = null;
        mResolver = null;
        mPrefsInited = false;
    }
}
Also used : ContentResolver(android.content.ContentResolver)

Example 39 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class ConnectivityServiceTest method setMobileDataAlwaysOn.

private void setMobileDataAlwaysOn(boolean enable) {
    ContentResolver cr = mServiceContext.getContentResolver();
    Settings.Global.putInt(cr, Settings.Global.MOBILE_DATA_ALWAYS_ON, enable ? 1 : 0);
    mService.updateMobileDataAlwaysOn();
    mService.waitForIdle();
}
Also used : ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver)

Example 40 with ContentResolver

use of android.content.ContentResolver in project platform_frameworks_base by android.

the class ConnectivityServiceTest method testMobileDataAlwaysOn.

@SmallTest
public void testMobileDataAlwaysOn() throws Exception {
    final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
    final NetworkRequest cellRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();
    mCm.registerNetworkCallback(cellRequest, cellNetworkCallback);
    final HandlerThread handlerThread = new HandlerThread("MobileDataAlwaysOnFactory");
    handlerThread.start();
    NetworkCapabilities filter = new NetworkCapabilities().addTransportType(TRANSPORT_CELLULAR).addCapability(NET_CAPABILITY_INTERNET);
    final MockNetworkFactory testFactory = new MockNetworkFactory(handlerThread.getLooper(), mServiceContext, "testFactory", filter);
    testFactory.setScoreFilter(40);
    // Register the factory and expect it to start looking for a network.
    testFactory.expectAddRequests(1);
    testFactory.register();
    testFactory.waitForNetworkRequests(1);
    assertTrue(testFactory.getMyStartRequested());
    // Bring up wifi. The factory stops looking for a network.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    // Because the default request changes score twice.
    testFactory.expectAddRequests(2);
    mWiFiNetworkAgent.connect(true);
    testFactory.waitForNetworkRequests(1);
    assertFalse(testFactory.getMyStartRequested());
    ContentResolver cr = mServiceContext.getContentResolver();
    // Turn on mobile data always on. The factory starts looking again.
    testFactory.expectAddRequests(1);
    setMobileDataAlwaysOn(true);
    testFactory.waitForNetworkRequests(2);
    assertTrue(testFactory.getMyStartRequested());
    // Bring up cell data and check that the factory stops looking.
    assertEquals(1, mCm.getAllNetworks().length);
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    // Because the cell request changes score twice.
    testFactory.expectAddRequests(2);
    mCellNetworkAgent.connect(true);
    cellNetworkCallback.expectAvailableAndValidatedCallbacks(mCellNetworkAgent);
    testFactory.waitForNetworkRequests(2);
    // Because the cell network outscores us.
    assertFalse(testFactory.getMyStartRequested());
    // Check that cell data stays up.
    mService.waitForIdle();
    verifyActiveNetwork(TRANSPORT_WIFI);
    assertEquals(2, mCm.getAllNetworks().length);
    // Turn off mobile data always on and expect the request to disappear...
    testFactory.expectRemoveRequests(1);
    setMobileDataAlwaysOn(false);
    testFactory.waitForNetworkRequests(1);
    // ...  and cell data to be torn down.
    cellNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    assertEquals(1, mCm.getAllNetworks().length);
    testFactory.unregister();
    mCm.unregisterNetworkCallback(cellNetworkCallback);
    handlerThread.quit();
}
Also used : HandlerThread(android.os.HandlerThread) NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities) ContentResolver(android.content.ContentResolver) MockContentResolver(android.test.mock.MockContentResolver) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ContentResolver (android.content.ContentResolver)1198 Uri (android.net.Uri)243 Cursor (android.database.Cursor)196 ContentValues (android.content.ContentValues)116 Intent (android.content.Intent)94 RemoteException (android.os.RemoteException)67 IOException (java.io.IOException)62 Context (android.content.Context)58 ArrayList (java.util.ArrayList)50 File (java.io.File)48 Resources (android.content.res.Resources)46 ComponentName (android.content.ComponentName)44 MediumTest (android.test.suitebuilder.annotation.MediumTest)37 PreferenceScreen (android.support.v7.preference.PreferenceScreen)35 Bitmap (android.graphics.Bitmap)33 ContentObserver (android.database.ContentObserver)28 FileNotFoundException (java.io.FileNotFoundException)28 PendingIntent (android.app.PendingIntent)25 MockContentResolver (android.test.mock.MockContentResolver)25 AssetFileDescriptor (android.content.res.AssetFileDescriptor)24