blob: 26703c514a962486de1133e3cc87d239c7c3022d [file] [log] [blame]
Jeff Brown6f357d32014-01-15 20:40:55 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import android.os.HandlerThread;
20import android.os.Process;
21import android.os.StrictMode;
Jeff Brown6f357d32014-01-15 20:40:55 -080022
23/**
24 * Special handler thread that we create for system services that require their own loopers.
25 */
Jeff Brown4ccb8232014-01-16 22:16:42 -080026public class ServiceThread extends HandlerThread {
Jeff Brown6f357d32014-01-15 20:40:55 -080027 private static final String TAG = "ServiceThread";
28
Jeff Brown4ccb8232014-01-16 22:16:42 -080029 private final boolean mAllowIo;
30
31 public ServiceThread(String name, int priority, boolean allowIo) {
Jeff Brown6f357d32014-01-15 20:40:55 -080032 super(name, priority);
Jeff Brown4ccb8232014-01-16 22:16:42 -080033 mAllowIo = allowIo;
Jeff Brown6f357d32014-01-15 20:40:55 -080034 }
35
36 @Override
37 public void run() {
38 Process.setCanSelfBackground(false);
39
Jeff Sharkey89182982017-11-01 19:02:56 -060040 if (!mAllowIo) {
41 StrictMode.initThreadDefaults(null);
Jeff Brown6f357d32014-01-15 20:40:55 -080042 }
43
44 super.run();
45 }
Jeff Sharkey89182982017-11-01 19:02:56 -060046}