diff options
author | keunyoung <keunyoung@google.com> | 2015-10-16 17:34:33 -0700 |
---|---|---|
committer | Rakesh Iyer <rni@google.com> | 2015-11-17 15:04:56 -0800 |
commit | 564742eab88bd68075e13b0b6505f637250f3fbc (patch) | |
tree | b928c539fe286392f583559ca97404036af2384e | |
parent | 38ba530c19774f5f27209dafa788e4d67759587a (diff) | |
download | Car-564742eab88bd68075e13b0b6505f637250f3fbc.tar.gz |
sensor renaming and add carservicetest
- move sensor API to android.support.car.hardware and
- move mocked test to carservice_test
- api_test will only use car API to test
bug: 23147726
Change-Id: I0f6870b6714b4042ec1213edb8500548cf789a8a
(cherry picked from commit abbd2b29e7dca10d1b9384767ab587fa314fe5b6)
21 files changed, 213 insertions, 32 deletions
diff --git a/carsupport-lib/src/android/support/car/CarServiceLoader.java b/carsupport-lib/src/android/support/car/CarServiceLoader.java index ac5c29e020..80a92796ad 100644 --- a/carsupport-lib/src/android/support/car/CarServiceLoader.java +++ b/carsupport-lib/src/android/support/car/CarServiceLoader.java @@ -19,6 +19,8 @@ package android.support.car; import android.content.Context; import android.os.IBinder; import android.os.Looper; +import android.support.car.hardware.CarSensorManager; +import android.support.car.hardware.ICarSensor; /** * CarServiceLoader is the abstraction for loading different types of car service. diff --git a/carsupport-lib/src/android/support/car/CarSensorEvent.aidl b/carsupport-lib/src/android/support/car/hardware/CarSensorEvent.aidl index 5aea5d3bf6..433221b561 100644 --- a/carsupport-lib/src/android/support/car/CarSensorEvent.aidl +++ b/carsupport-lib/src/android/support/car/hardware/CarSensorEvent.aidl @@ -14,6 +14,6 @@ * limitations under the License. */ -package android.support.car; +package android.support.car.hardware; parcelable CarSensorEvent; diff --git a/carsupport-lib/src/android/support/car/CarSensorEvent.java b/carsupport-lib/src/android/support/car/hardware/CarSensorEvent.java index 2b878f7bab..11a46527c7 100644 --- a/carsupport-lib/src/android/support/car/CarSensorEvent.java +++ b/carsupport-lib/src/android/support/car/hardware/CarSensorEvent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.support.car; +package android.support.car.hardware; import android.location.GpsSatellite; import android.location.Location; diff --git a/carsupport-lib/src/android/support/car/CarSensorManager.java b/carsupport-lib/src/android/support/car/hardware/CarSensorManager.java index 20eafe759f..7aacdf1a35 100644 --- a/carsupport-lib/src/android/support/car/CarSensorManager.java +++ b/carsupport-lib/src/android/support/car/hardware/CarSensorManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.support.car; +package android.support.car.hardware; import android.Manifest; import android.annotation.RequiresPermission; @@ -24,6 +24,11 @@ import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.Handler.Callback; +import android.support.car.Car; +import android.support.car.CarApiUtil; +import android.support.car.CarLibLog; +import android.support.car.CarManagerBase; +import android.support.car.CarNotConnectedException; import android.util.Log; import java.lang.ref.WeakReference; @@ -164,7 +169,7 @@ public class CarSensorManager implements CarManagerBase { /** @hide */ - CarSensorManager(Context context, ICarSensor service, Looper looper) { + public CarSensorManager(Context context, ICarSensor service, Looper looper) { mService = service; mServiceVersion = getVersion(); if (mServiceVersion < VERSION) { diff --git a/carsupport-lib/src/android/support/car/ICarSensor.aidl b/carsupport-lib/src/android/support/car/hardware/ICarSensor.aidl index b82d8e6193..a902d8f09e 100644 --- a/carsupport-lib/src/android/support/car/ICarSensor.aidl +++ b/carsupport-lib/src/android/support/car/hardware/ICarSensor.aidl @@ -14,10 +14,10 @@ * limitations under the License. */ -package android.support.car; +package android.support.car.hardware; -import android.support.car.CarSensorEvent; -import android.support.car.ICarSensorEventListener; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.ICarSensorEventListener; /** @hide */ interface ICarSensor { diff --git a/carsupport-lib/src/android/support/car/ICarSensorEventListener.aidl b/carsupport-lib/src/android/support/car/hardware/ICarSensorEventListener.aidl index 129f9810ab..ec547d5998 100644 --- a/carsupport-lib/src/android/support/car/ICarSensorEventListener.aidl +++ b/carsupport-lib/src/android/support/car/hardware/ICarSensorEventListener.aidl @@ -14,9 +14,9 @@ * limitations under the License. */ -package android.support.car; +package android.support.car.hardware; -import android.support.car.CarSensorEvent; +import android.support.car.hardware.CarSensorEvent; /** * Binder callback for CarSensorEventListener. diff --git a/service/src/com/android/car/CarSensorEventFactory.java b/service/src/com/android/car/CarSensorEventFactory.java index 35c29fa8fc..7940f9a958 100644 --- a/service/src/com/android/car/CarSensorEventFactory.java +++ b/service/src/com/android/car/CarSensorEventFactory.java @@ -16,7 +16,7 @@ package com.android.car; -import android.support.car.CarSensorEvent; +import android.support.car.hardware.CarSensorEvent; //TODO add memory pool and recycling public class CarSensorEventFactory { diff --git a/service/src/com/android/car/CarSensorService.java b/service/src/com/android/car/CarSensorService.java index cffb37e387..6b584e32fc 100644 --- a/service/src/com/android/car/CarSensorService.java +++ b/service/src/com/android/car/CarSensorService.java @@ -30,11 +30,11 @@ import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.support.car.Car; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; -import android.support.car.ICarSensor; -import android.support.car.ICarSensorEventListener; -import android.support.car.CarSensorManager.CarSensorEventListener; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; +import android.support.car.hardware.ICarSensor; +import android.support.car.hardware.ICarSensorEventListener; +import android.support.car.hardware.CarSensorManager.CarSensorEventListener; import android.util.Log; import android.util.SparseArray; import android.util.SparseBooleanArray; diff --git a/service/src/com/android/car/DayNightModePolicy.java b/service/src/com/android/car/DayNightModePolicy.java index 892c077855..8f9b60b4ba 100644 --- a/service/src/com/android/car/DayNightModePolicy.java +++ b/service/src/com/android/car/DayNightModePolicy.java @@ -19,8 +19,8 @@ package com.android.car; import android.content.Context; import android.os.SystemClock; import android.support.car.Car; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; import com.android.car.hal.SensorHalServiceBase.SensorListener; diff --git a/service/src/com/android/car/DrivingStatePolicy.java b/service/src/com/android/car/DrivingStatePolicy.java index 11fad669df..41f1e1aba3 100644 --- a/service/src/com/android/car/DrivingStatePolicy.java +++ b/service/src/com/android/car/DrivingStatePolicy.java @@ -19,9 +19,9 @@ package com.android.car; import android.content.Context; import android.os.SystemClock; import android.support.car.Car; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; -import android.support.car.ICarSensorEventListener; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; +import android.support.car.hardware.ICarSensorEventListener; import android.util.Log; import com.android.car.hal.SensorHalServiceBase.SensorListener; diff --git a/service/src/com/android/car/hal/SensorHalService.java b/service/src/com/android/car/hal/SensorHalService.java index e7fb8f40cc..5cd7258e67 100644 --- a/service/src/com/android/car/hal/SensorHalService.java +++ b/service/src/com/android/car/hal/SensorHalService.java @@ -16,8 +16,8 @@ package com.android.car.hal; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; import android.util.Log; import android.util.SparseArray; diff --git a/service/src/com/android/car/hal/SensorHalServiceBase.java b/service/src/com/android/car/hal/SensorHalServiceBase.java index d56797fdb6..3e2fee1400 100644 --- a/service/src/com/android/car/hal/SensorHalServiceBase.java +++ b/service/src/com/android/car/hal/SensorHalServiceBase.java @@ -16,7 +16,7 @@ package com.android.car.hal; -import android.support.car.CarSensorEvent; +import android.support.car.hardware.CarSensorEvent; import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropConfig; import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValue; diff --git a/tests/api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java b/tests/api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java index ccaef131c2..441213bd08 100644 --- a/tests/api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java +++ b/tests/api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java @@ -20,9 +20,9 @@ import android.content.ComponentName; import android.os.IBinder; import android.os.Looper; import android.support.car.Car; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; import android.support.car.ServiceConnectionListener; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; import android.test.AndroidTestCase; import java.util.concurrent.Semaphore; diff --git a/tests/api_test/src/com/android/support/car/apitest/CarTest.java b/tests/api_test/src/com/android/support/car/apitest/CarTest.java index 60f7ee6666..8a8cc3dfe5 100644 --- a/tests/api_test/src/com/android/support/car/apitest/CarTest.java +++ b/tests/api_test/src/com/android/support/car/apitest/CarTest.java @@ -20,7 +20,7 @@ import android.content.ComponentName; import android.os.IBinder; import android.os.Looper; import android.support.car.Car; -import android.support.car.CarSensorManager; +import android.support.car.hardware.CarSensorManager; import android.support.car.ServiceConnectionListener; import android.test.AndroidTestCase; diff --git a/tests/car_activity_test_app/src/com/android/support/car/test/caractivitytest/HelloCarActivity.java b/tests/car_activity_test_app/src/com/android/support/car/test/caractivitytest/HelloCarActivity.java index 2701ba5c9e..5c9f287628 100644 --- a/tests/car_activity_test_app/src/com/android/support/car/test/caractivitytest/HelloCarActivity.java +++ b/tests/car_activity_test_app/src/com/android/support/car/test/caractivitytest/HelloCarActivity.java @@ -21,10 +21,10 @@ import android.os.Bundle; import android.support.car.Car; import android.support.car.CarNotConnectedException; import android.support.car.CarNotSupportedException; -import android.support.car.CarSensorEvent; -import android.support.car.CarSensorManager; -import android.support.car.CarSensorManager.CarSensorEventListener; import android.support.car.app.CarActivity; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; +import android.support.car.hardware.CarSensorManager.CarSensorEventListener; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; diff --git a/tests/carservice_test/Android.mk b/tests/carservice_test/Android.mk new file mode 100644 index 0000000000..14160c6b3c --- /dev/null +++ b/tests/carservice_test/Android.mk @@ -0,0 +1,39 @@ +# Copyright (C) 2015 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. +# +# + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := CarServiceTest + +# for system|priviledged permission. +LOCAL_CERTIFICATE := platform + +LOCAL_MODULE_TAGS := tests + +# When built explicitly put it in the data partition +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_STATIC_JAVA_LIBRARIES += libcarsystemtest + +LOCAL_JAVA_LIBRARIES := android.test.runner + +include $(BUILD_PACKAGE) diff --git a/tests/carservice_test/AndroidManifest.xml b/tests/carservice_test/AndroidManifest.xml new file mode 100644 index 0000000000..ac6591aa01 --- /dev/null +++ b/tests/carservice_test/AndroidManifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2015 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + package="com.android.support.car.carservicetest" + android:sharedUserId="android.uid.system" > + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.support.car.carservicetest" + android:label="Tests for Car APIs"/> + + <application android:label="CarServiceTest"> + <uses-library android:name="android.test.runner" /> + </application> +</manifest> diff --git a/tests/api_test/src/com/android/support/car/apitest/CarAudioTest.java b/tests/carservice_test/src/com/android/support/car/test/CarAudioTest.java index e51aaebf83..3b6c870b25 100644 --- a/tests/api_test/src/com/android/support/car/apitest/CarAudioTest.java +++ b/tests/carservice_test/src/com/android/support/car/test/CarAudioTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.support.car.apitest; +package com.android.support.car.test; import android.content.Context; import android.media.AudioManager; diff --git a/tests/api_test/src/com/android/support/car/apitest/CarInfoManagerTest.java b/tests/carservice_test/src/com/android/support/car/test/CarInfoManagerTest.java index d14a1ed335..41441feb55 100644 --- a/tests/api_test/src/com/android/support/car/apitest/CarInfoManagerTest.java +++ b/tests/carservice_test/src/com/android/support/car/test/CarInfoManagerTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.support.car.apitest; +package com.android.support.car.test; import android.content.ComponentName; import android.os.IBinder; diff --git a/tests/carservice_test/src/com/android/support/car/test/CarSensorManagerTest.java b/tests/carservice_test/src/com/android/support/car/test/CarSensorManagerTest.java new file mode 100644 index 0000000000..f4ee96b0d9 --- /dev/null +++ b/tests/carservice_test/src/com/android/support/car/test/CarSensorManagerTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2015 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.support.car.test; + +import android.content.ComponentName; +import android.os.IBinder; +import android.os.Looper; +import android.support.car.Car; +import android.support.car.ServiceConnectionListener; +import android.support.car.hardware.CarSensorEvent; +import android.support.car.hardware.CarSensorManager; +import android.test.AndroidTestCase; + +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +/** TODO change to mocking +public class CarSensorManagerTest extends AndroidTestCase { + private static final long DEFAULT_WAIT_TIMEOUT_MS = 3000; + + private final Semaphore mConnectionWait = new Semaphore(0); + + private Car mCar; + private CarSensorManager mCarSensorManager; + + private final ServiceConnectionListener mConnectionListener = new ServiceConnectionListener() { + + @Override + public void onServiceSuspended(int cause) { + assertMainThread(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + assertMainThread(); + } + + @Override + public void onServiceConnectionFailed(int cause) { + assertMainThread(); + } + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + assertMainThread(); + mConnectionWait.release(); + } + }; + + private void assertMainThread() { + assertTrue(Looper.getMainLooper().isCurrentThread()); + } + private void waitForConnection(long timeoutMs) throws InterruptedException { + mConnectionWait.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mCar = new Car(getContext(), mConnectionListener, null); + mCar.connect(); + waitForConnection(DEFAULT_WAIT_TIMEOUT_MS); + mCarSensorManager = + (CarSensorManager) mCar.getCarManager(Car.SENSOR_SERVICE); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + mCar.disconnect(); + } + + public void testDrivingPolicy() throws Exception { + int[] supportedSensors = mCarSensorManager.getSupportedSensors(); + assertNotNull(supportedSensors); + boolean found = false; + for (int sensor: supportedSensors) { + if (sensor == CarSensorManager.SENSOR_TYPE_DRIVING_STATUS) { + found = true; + break; + } + } + assertTrue(found); + assertTrue(mCarSensorManager.isSensorSupported( + CarSensorManager.SENSOR_TYPE_DRIVING_STATUS)); + assertTrue(CarSensorManager.isSensorSupported(supportedSensors, + CarSensorManager.SENSOR_TYPE_DRIVING_STATUS)); + CarSensorEvent lastEvent = mCarSensorManager.getLatestSensorEvent( + CarSensorManager.SENSOR_TYPE_DRIVING_STATUS); + assertNotNull(lastEvent); + } +}*/ diff --git a/tests/api_test/src/com/android/support/car/apitest/MockedCarTestBase.java b/tests/carservice_test/src/com/android/support/car/test/MockedCarTestBase.java index db3d52d006..502f8065bb 100644 --- a/tests/api_test/src/com/android/support/car/apitest/MockedCarTestBase.java +++ b/tests/carservice_test/src/com/android/support/car/test/MockedCarTestBase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.support.car.apitest; +package com.android.support.car.test; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; |