1 /* 2 * Copyright (C) 2019 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 17 package com.android.experimentalcar; 18 19 import android.app.Service; 20 import android.car.Car; 21 import android.content.Intent; 22 import android.os.IBinder; 23 24 import java.io.FileDescriptor; 25 import java.io.PrintWriter; 26 27 /** 28 * Top class to keep all experimental features. 29 */ 30 public class ExperimentalCarService extends Service { 31 32 private Car mCar; 33 private final IExperimentalCarImpl mIExperimentalCarImpl = new IExperimentalCarImpl(this); 34 35 @Override onCreate()36 public void onCreate() { 37 super.onCreate(); 38 // This is for crashing this service when car service crashes. 39 mCar = Car.createCar(this); 40 } 41 42 @Override onDestroy()43 public void onDestroy() { 44 mIExperimentalCarImpl.release(); 45 if (mCar != null && mCar.isConnected()) { 46 mCar.disconnect(); 47 mCar = null; 48 } 49 super.onDestroy(); 50 } 51 52 @Override onStartCommand(Intent intent, int flags, int startId)53 public int onStartCommand(Intent intent, int flags, int startId) { 54 // keep it alive. 55 return START_STICKY; 56 } 57 58 @Override onBind(Intent intent)59 public IBinder onBind(Intent intent) { 60 return mIExperimentalCarImpl; 61 } 62 63 @Override dump(FileDescriptor fd, PrintWriter writer, String[] args)64 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { 65 mIExperimentalCarImpl.dump(fd, writer, args); 66 } 67 } 68