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 */
16package com.android.car;
17
18import java.io.FileDescriptor;
19import java.io.PrintWriter;
20
21import com.android.car.hal.VehicleHal;
22
23import android.app.Service;
24import android.car.Car;
25import android.content.Intent;
26import android.os.IBinder;
27import android.util.Log;
28
29public class CarService extends Service {
30
31    // main thread only
32    private ICarImpl mICarImpl;
33
34    @Override
35    public void onCreate() {
36        Log.i(CarLog.TAG_SERVICE, "Service onCreate");
37        mICarImpl = ICarImpl.getInstance(this);
38        super.onCreate();
39    }
40
41    @Override
42    public void onDestroy() {
43        Log.i(CarLog.TAG_SERVICE, "Service onDestroy");
44        ICarImpl.releaseInstance();
45        super.onDestroy();
46    }
47
48    @Override
49    public int onStartCommand(Intent intent, int flags, int startId) {
50        // keep it alive.
51        return START_STICKY;
52    }
53
54    @Override
55    public IBinder onBind(Intent intent) {
56        return mICarImpl;
57    }
58
59    @Override
60    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
61        writer.println("*dump car service*");
62        writer.println("*dump HAL*");
63        VehicleHal.getInstance().dump(writer);
64        writer.println("*dump services*");
65        ICarImpl.getInstance(this).dump(writer);
66    }
67}
68