Loading core/java/com/android/internal/content/PackageMonitor.java +2 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.UserHandle; import com.android.internal.os.BackgroundThread; import java.util.HashSet; Loading @@ -37,10 +38,6 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { static final IntentFilter sNonDataFilt = new IntentFilter(); static final IntentFilter sExternalFilt = new IntentFilter(); static final Object sLock = new Object(); static HandlerThread sBackgroundThread; static Handler sBackgroundHandler; static { sPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); Loading Loading @@ -79,15 +76,7 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { } mRegisteredContext = context; if (thread == null) { synchronized (sLock) { if (sBackgroundThread == null) { sBackgroundThread = new HandlerThread("PackageMonitor", android.os.Process.THREAD_PRIORITY_BACKGROUND); sBackgroundThread.start(); sBackgroundHandler = new Handler(sBackgroundThread.getLooper()); } mRegisteredHandler = sBackgroundHandler; } mRegisteredHandler = BackgroundThread.getHandler(); } else { mRegisteredHandler = new Handler(thread); } Loading core/java/com/android/internal/os/BackgroundThread.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.os; import android.os.Handler; import android.os.HandlerThread; /** * Shared singleton background thread for each process. */ public final class BackgroundThread extends HandlerThread { private static BackgroundThread sInstance; private static Handler sHandler; private BackgroundThread() { super("android.bg", android.os.Process.THREAD_PRIORITY_BACKGROUND); } private static void ensureThreadLocked() { if (sInstance == null) { sInstance = new BackgroundThread(); sInstance.start(); sHandler = new Handler(sInstance.getLooper()); } } public static BackgroundThread get() { synchronized (BackgroundThread.class) { ensureThreadLocked(); return sInstance; } } public static Handler getHandler() { synchronized (BackgroundThread.class) { ensureThreadLocked(); return sHandler; } } } services/java/com/android/server/AppWidgetService.java +2 −4 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; Loading @@ -37,6 +36,7 @@ import android.widget.RemoteViews; import com.android.internal.appwidget.IAppWidgetHost; import com.android.internal.appwidget.IAppWidgetService; import com.android.internal.os.BackgroundThread; import com.android.internal.util.IndentingPrintWriter; import java.io.FileDescriptor; Loading @@ -63,9 +63,7 @@ class AppWidgetService extends IAppWidgetService.Stub AppWidgetService(Context context) { mContext = context; HandlerThread handlerThread = new HandlerThread("AppWidgetService -- Save state"); handlerThread.start(); mSaveStateHandler = new Handler(handlerThread.getLooper()); mSaveStateHandler = BackgroundThread.getHandler(); mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5); AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler); Loading services/java/com/android/server/BluetoothManagerService.java +1 −5 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.os.Message; Loading Loading @@ -115,7 +114,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // used inside handler thread private boolean mEnable; private int mState; private HandlerThread mThread; private final BluetoothHandler mHandler; private void registerForAirplaneMode(IntentFilter filter) { Loading Loading @@ -188,9 +186,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { }; BluetoothManagerService(Context context) { mThread = new HandlerThread("BluetoothManager"); mThread.start(); mHandler = new BluetoothHandler(mThread.getLooper()); mHandler = new BluetoothHandler(IoThread.get().getLooper()); mContext = context; mBluetooth = null; Loading services/java/com/android/server/CountryDetectorService.java +2 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.HashMap; import com.android.internal.os.BackgroundThread; import com.android.server.location.ComprehensiveCountryDetector; import android.content.Context; Loading @@ -29,8 +30,6 @@ import android.location.ICountryDetector; import android.location.ICountryListener; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.util.PrintWriterPrinter; import android.util.Printer; Loading Loading @@ -169,8 +168,7 @@ public class CountryDetectorService extends ICountryDetector.Stub implements Run void systemReady() { // Shall we wait for the initialization finish. Thread thread = new Thread(this, "CountryDetectorService"); thread.start(); BackgroundThread.getHandler().post(this); } private void initialize() { Loading @@ -187,12 +185,9 @@ public class CountryDetectorService extends ICountryDetector.Stub implements Run } public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Looper.prepare(); mHandler = new Handler(); initialize(); mSystemReady = true; Looper.loop(); } protected void setCountryListener(final CountryListener listener) { Loading Loading
core/java/com/android/internal/content/PackageMonitor.java +2 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.UserHandle; import com.android.internal.os.BackgroundThread; import java.util.HashSet; Loading @@ -37,10 +38,6 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { static final IntentFilter sNonDataFilt = new IntentFilter(); static final IntentFilter sExternalFilt = new IntentFilter(); static final Object sLock = new Object(); static HandlerThread sBackgroundThread; static Handler sBackgroundHandler; static { sPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); Loading Loading @@ -79,15 +76,7 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { } mRegisteredContext = context; if (thread == null) { synchronized (sLock) { if (sBackgroundThread == null) { sBackgroundThread = new HandlerThread("PackageMonitor", android.os.Process.THREAD_PRIORITY_BACKGROUND); sBackgroundThread.start(); sBackgroundHandler = new Handler(sBackgroundThread.getLooper()); } mRegisteredHandler = sBackgroundHandler; } mRegisteredHandler = BackgroundThread.getHandler(); } else { mRegisteredHandler = new Handler(thread); } Loading
core/java/com/android/internal/os/BackgroundThread.java 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.os; import android.os.Handler; import android.os.HandlerThread; /** * Shared singleton background thread for each process. */ public final class BackgroundThread extends HandlerThread { private static BackgroundThread sInstance; private static Handler sHandler; private BackgroundThread() { super("android.bg", android.os.Process.THREAD_PRIORITY_BACKGROUND); } private static void ensureThreadLocked() { if (sInstance == null) { sInstance = new BackgroundThread(); sInstance.start(); sHandler = new Handler(sInstance.getLooper()); } } public static BackgroundThread get() { synchronized (BackgroundThread.class) { ensureThreadLocked(); return sInstance; } } public static Handler getHandler() { synchronized (BackgroundThread.class) { ensureThreadLocked(); return sHandler; } } }
services/java/com/android/server/AppWidgetService.java +2 −4 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; Loading @@ -37,6 +36,7 @@ import android.widget.RemoteViews; import com.android.internal.appwidget.IAppWidgetHost; import com.android.internal.appwidget.IAppWidgetService; import com.android.internal.os.BackgroundThread; import com.android.internal.util.IndentingPrintWriter; import java.io.FileDescriptor; Loading @@ -63,9 +63,7 @@ class AppWidgetService extends IAppWidgetService.Stub AppWidgetService(Context context) { mContext = context; HandlerThread handlerThread = new HandlerThread("AppWidgetService -- Save state"); handlerThread.start(); mSaveStateHandler = new Handler(handlerThread.getLooper()); mSaveStateHandler = BackgroundThread.getHandler(); mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5); AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler); Loading
services/java/com/android/server/BluetoothManagerService.java +1 −5 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.os.Message; Loading Loading @@ -115,7 +114,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // used inside handler thread private boolean mEnable; private int mState; private HandlerThread mThread; private final BluetoothHandler mHandler; private void registerForAirplaneMode(IntentFilter filter) { Loading Loading @@ -188,9 +186,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { }; BluetoothManagerService(Context context) { mThread = new HandlerThread("BluetoothManager"); mThread.start(); mHandler = new BluetoothHandler(mThread.getLooper()); mHandler = new BluetoothHandler(IoThread.get().getLooper()); mContext = context; mBluetooth = null; Loading
services/java/com/android/server/CountryDetectorService.java +2 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.HashMap; import com.android.internal.os.BackgroundThread; import com.android.server.location.ComprehensiveCountryDetector; import android.content.Context; Loading @@ -29,8 +30,6 @@ import android.location.ICountryDetector; import android.location.ICountryListener; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.util.PrintWriterPrinter; import android.util.Printer; Loading Loading @@ -169,8 +168,7 @@ public class CountryDetectorService extends ICountryDetector.Stub implements Run void systemReady() { // Shall we wait for the initialization finish. Thread thread = new Thread(this, "CountryDetectorService"); thread.start(); BackgroundThread.getHandler().post(this); } private void initialize() { Loading @@ -187,12 +185,9 @@ public class CountryDetectorService extends ICountryDetector.Stub implements Run } public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Looper.prepare(); mHandler = new Handler(); initialize(); mSystemReady = true; Looper.loop(); } protected void setCountryListener(final CountryListener listener) { Loading