Device management service

Device management services provide local device management operations, such as: set the watch left / right hand wear, install / remove applications, unbind the watch, get binding status, etc.

Basic concept

DeviceManagerService

Representing device management core service, a collection of settings for the left / right hand wrist watch to wear, install / delete / get application information, binding status management, BLE broadcast management, set Bluetooth scanning mode, Bluetooth and power reduction strategy.

DeviceManagerServiceManager

Representing a series of public interfaces for device management services such as setting the watch's left / right hand style, installing / removing applications, unbinding the watch, and getting the binding status.

// set to right or left hand wear mode 
public void setWearOnRightHand(boolean isOnRightHand);

//juege device is right or left hand
public boolean isWearOnRightHand();

//delete APP
public void deletePackage(String packageName);

//delete APP data and cache
public void deleteAllAppDataAndCache();

//get bond status
public boolean getBondStatus();

//get bond type
public int getBondType();

//get bond device descriptor
public DeviceDescriptor getBondDescriptor();

//start ble advertise
public void startAdvertising(AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseData scanResponse, IIwdsAdvertiseCallback callback);

//stop ble advertise
public void stopAdvertising(IIwdsAdvertiseCallback callback);

//set bluetooth scan mode
public boolean setBluetoothScanMode(int mode);

//get bluetooth scan mode
public int getBluetoothScanMode();

IIwdsAdvertiseCallback

Representing BluetoothLeAdvertiseManager start/stop BLE advertise callback,It is AIDL generated interface, the user needs to achieve its server, and the original and the Android AdvertiseCallback provide the same interface.

// IIwdsAdvertiseCallback.aidl
interface IIwdsAdvertiseCallback {
    void onStartSuccess(in AdvertiseSettings settingsInEffect);
    void onStartFailure(in int errorCode);
}

Instructions

1. The first through the ServiceClient object and passed SERVICE_DEVICE_MANAGER parameters connected device management services.

private ServiceClient m_serviceClient;
private DeviceManagerServiceManager m_deviceManager;
m_serviceClient = new ServiceClient(getAppContext(), ServiceManagerContext.SERVICE_DEVICE_MANAGER, mServiceCallback);
m_serviceClient.connect();

2. And then connect the success of the callback function to get DeviceManagerServiceManager device management service instance object, access to the DeviceManagerServiceManager instance can call its public interface for device management-related operations.

//in mServiceCallback callack onConnected get DeviceManagerServiceManager instance
public void onConnected(ServiceClient serviceClient) {
    m_deviceManager = (DeviceManagerServiceManager) serviceClient.getServiceManagerContext();
    boolean isBond = m_deviceManager.getBondStatus();
    ... ...
}

Bond state and power reduction policy

Uniconnect service intruct that Link represent an actual physical connection, support and Android system, the classic Bluetooth connection (link referred to as BT Link), and IOS system to support low-power Bluetooth connection (link referred to as BLE Link) , We specify the watch can only be connected with one mobile phone at the same time, BT Link and BLE Link at the same time only one link in use, the other link which is not used will to be closed to reduce power consumption. Also, when using BT Link, if the link is already connected, you can switch the classic Bluetooth scan mode to None mode. To do this we need to record the Link type and device info, we added the binding state.

Bond state

Mobile phone and watch connected to each other, both recording device descriptor (DeviceDescripter type, including details of the equipment), record the bound state (type Boolean, true binding /false unlasing), record the binding type (there are three kinds of values: ingenic BT binding, ingenic BLE binding, BLE binding, Other restart) can know before connecting the equipment, so we restart according to the recorded binding equipment of Link type (BT/BLE), to decide which link to start, reduce power.

Rules:

  1. Watch and phone both make rules that the first successful connection (ACTION_CONNECTED_ADDRESS broadcast received) is bond status, the both side need to save device descriptor, bond state, binding type stored in SharedPreferences.
    if (ConnectionServiceManager.ACTION_CONNECTED_ADDRESS.equals(action)) {
        DeviceDescriptor descriptor = intent.getParcelableExtra("DeviceDescriptor");
        synchronized (mLocked) {
            if (!mIsBondWatch) { //not bond before
                mIsBondWatch = true;
                mBondDescriptor = descriptor;
                broadcastBondStatusChange(mIsBondWatch, mBondDescriptor);
                IwdsUtils.saveBondStatus(mContext, mIsBondWatch); //save bond status
                IwdsUtils.saveBondDescriptor(mContext, mBondDescriptor); //save DeviceDescripter
            }
        }
    }
        
  2. When the mobile phone and watch away from or switch Bluetooth, etc., will link Link disconnected, but the binding state remains unchanged; need to initiate mobile phone unbind request to be received after the request to remove the watch (remote device management introduced) Binding relationship, clear the record storage of binding information.
  3. When the mobile phone and watch away from or switch Bluetooth, etc., will link Link disconnected, but the binding state remains unchanged; need to initiate mobile phone unbind request to be received after the request to remove the watch (remote device management introduced) Binding relationship, clear the record storage of binding information.

    private boolean bondAddressLocked(String pkg, String addr) {
            if (mIsBondWatch && mBondDescriptor != null
                    && !mBondDescriptor.devAddress.equals(addr)) {
                return false;
            }
        ... ...
    }

  4. Once the binding is successful, do not display the QR code until the binding relationship is lifted.

Reduce power policy

Link represents the actual physical link, which is divided into the server and client, the server runs on the watch side, waiting for real-time client to connect; client running on the phone side, mobile phones by scanning the Bluetooth code with a two-dimensional code and .

Ingenic Has achieved good general strategy

  1. If the phone is Android system through the BT Link connection binding, binding can be successful after the BLE Link watch off, stop BLE broadcast.
  2. If IOS system is connected through the BLE Link binding, binding can be successful after the watch BT Link off, the classic Bluetooth scan mode is set to None.
  3. If the BT Link connection is successful, set the Classic Bluetooth Scan Mode to None; if the BT Link connection is disconnected, set the Classic Bluetooth Scan Mode to Connectable.

User specific needs

  1. There is a user-defined BLE connection, the use of our BT Link, do not use our BLE Link, we need to reduce power consumption strategy.
  2. A user does not need to bind the state of the king to carry out the strategy to reduce power consumption, just use Link's link state to do a simple strategy to reduce power consumption.

Therefore, we consider their general strategy and the special needs of customers, the definition of the following variables related properties, the user can choose to use according to demand.

1、The user needs to configure SystemProperties that key is named "ro.iwds.uniconnect.enableBle" and value is boolean to represent whether use Ingenic's BLE service.

2、The user needs to configure SystemProperties that key is named "ro.iwds.uniconnect.useBondState"and value is boolean,to represent whether use Ingenic's bond status to reduce power.

3、Users use their own definition of BLE connection services need to reduce the power-Jun Zheng strategy, you need to send action named "com.ingenic.otherBle.bondStateChange" and pass a boolean type paramter named "bond_state".

The specific power reduction strategies are listed below

whether use ingenic bond status to reduce power bond status bond type whether use Ingenic BLE service link connect status phone system reduce power policy
false     false false   stopBleServer()
startClassBtServer()
setScanMode(Connectable)
false     false true Android stopBleServer()
startClassBtServer()
setScanMode(None)
false     true false   startBleServer()
startClassBtServer()
setScanMode(Connectable)
false     true true Android stopBleServer()
startClassBtServer()
setScanMode(None)
false     true true IOS startBleServer()
stopClassBtServer()
setScanMode(None)
true false NONE true false   startBleServer()
startClassBtServer()
setScanMode(Connectable)
true true INGENIC_BT true false Android stopBleServer()
startClassBtServer()
setScanMode(Connectable)
true true INGENIC_BT true true Android stopBleServer()
startClassBtServer()
setScanMode(None)
true true INGENIC_BLE true false IOS startBleServer()
stopClassBtServer()
setScanMode(None)
true true INGENIC_BLE true true IOS startBleServer()
stopClassBtServer()
setScanMode(None)
true true OTHER_BLE false     stopBleServer()
stopClassBtServer()
setScanMode(None)