keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | package com.android.car; |
| 17 | |
| 18 | import java.io.FileDescriptor; |
| 19 | import java.io.PrintWriter; |
| 20 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 21 | import com.android.car.hal.VehicleHal; |
| 22 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 23 | import android.app.Service; |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 24 | import android.car.Car; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
| 26 | import android.os.IBinder; |
Vitalii Tomkiv | 973d2a2 | 2016-04-13 17:05:38 -0700 | [diff] [blame] | 27 | import android.os.SystemProperties; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
| 30 | public class CarService extends Service { |
| 31 | |
| 32 | // main thread only |
| 33 | private ICarImpl mICarImpl; |
| 34 | |
| 35 | @Override |
| 36 | public void onCreate() { |
| 37 | Log.i(CarLog.TAG_SERVICE, "Service onCreate"); |
| 38 | mICarImpl = ICarImpl.getInstance(this); |
Vitalii Tomkiv | 973d2a2 | 2016-04-13 17:05:38 -0700 | [diff] [blame] | 39 | SystemProperties.set("boot.car_service_created", "1"); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 40 | super.onCreate(); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void onDestroy() { |
| 45 | Log.i(CarLog.TAG_SERVICE, "Service onDestroy"); |
| 46 | ICarImpl.releaseInstance(); |
| 47 | super.onDestroy(); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public int onStartCommand(Intent intent, int flags, int startId) { |
| 52 | // keep it alive. |
| 53 | return START_STICKY; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public IBinder onBind(Intent intent) { |
| 58 | return mICarImpl; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 63 | writer.println("*dump car service*"); |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 64 | writer.println("*dump HAL*"); |
keunyoung | fe30ba0 | 2015-09-17 17:56:35 -0700 | [diff] [blame] | 65 | VehicleHal.getInstance().dump(writer); |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame] | 66 | writer.println("*dump services*"); |
| 67 | ICarImpl.getInstance(this).dump(writer); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 68 | } |
| 69 | } |