FileDocCategorySizeDatePackage
CommonTimeConfig.javaAPI DocAndroid 5.1 API18672Thu Mar 12 22:22:10 GMT 2015android.os

CommonTimeConfig

public class CommonTimeConfig extends Object
Used for configuring and controlling the status of the android common time service.
hide

Fields Summary
public static final int
SUCCESS
Successful operation.
public static final int
ERROR
Unspecified error.
public static final int
ERROR_BAD_VALUE
Operation failed due to bad parameter value.
public static final int
ERROR_DEAD_OBJECT
Operation failed due to dead remote object.
public static final long
INVALID_GROUP_ID
Sentinel value returned by {@link #getMasterElectionGroupId()} when an error occurs trying to fetch the master election group.
public static final String
SERVICE_NAME
Name of the underlying native binder service
private final Object
mListenerLock
private OnServerDiedListener
mServerDiedListener
private android.os.IBinder
mRemote
private String
mInterfaceDesc
private android.os.CommonTimeUtils
mUtils
private IBinder.DeathRecipient
mDeathHandler
private static final int
METHOD_GET_MASTER_ELECTION_PRIORITY
private static final int
METHOD_SET_MASTER_ELECTION_PRIORITY
private static final int
METHOD_GET_MASTER_ELECTION_ENDPOINT
private static final int
METHOD_SET_MASTER_ELECTION_ENDPOINT
private static final int
METHOD_GET_MASTER_ELECTION_GROUP_ID
private static final int
METHOD_SET_MASTER_ELECTION_GROUP_ID
private static final int
METHOD_GET_INTERFACE_BINDING
private static final int
METHOD_SET_INTERFACE_BINDING
private static final int
METHOD_GET_MASTER_ANNOUNCE_INTERVAL
private static final int
METHOD_SET_MASTER_ANNOUNCE_INTERVAL
private static final int
METHOD_GET_CLIENT_SYNC_INTERVAL
private static final int
METHOD_SET_CLIENT_SYNC_INTERVAL
private static final int
METHOD_GET_PANIC_THRESHOLD
private static final int
METHOD_SET_PANIC_THRESHOLD
private static final int
METHOD_GET_AUTO_DISABLE
private static final int
METHOD_SET_AUTO_DISABLE
private static final int
METHOD_FORCE_NETWORKLESS_MASTER_MODE
Constructors Summary
public CommonTimeConfig()
Class constructor.

throws
android.os.RemoteException


             
     
      
        mRemote = ServiceManager.getService(SERVICE_NAME);
        if (null == mRemote)
            throw new RemoteException();

        mInterfaceDesc = mRemote.getInterfaceDescriptor();
        mUtils = new CommonTimeUtils(mRemote, mInterfaceDesc);
        mRemote.linkToDeath(mDeathHandler, 0);
    
Methods Summary
private booleancheckDeadServer()

        return ((null == mRemote) || (null == mUtils));
    
public static android.os.CommonTimeConfigcreate()
Handy class factory method.

        CommonTimeConfig retVal;

        try {
            retVal = new CommonTimeConfig();
        }
        catch (RemoteException e) {
            retVal = null;
        }

        return retVal;
    
protected voidfinalize()

 release(); 
public intforceNetworklessMasterMode()
At startup, the time service enters the initial state and remains there until it is given a network interface to bind to. Common time will be unavailable to clients of the common time service until the service joins a network (even an empty network). Devices may use the {@link #forceNetworklessMasterMode()} method to force a time service in the INITIAL state with no network configuration to assume MASTER status for a brand new timeline in order to allow clients of the common time service to operate, even though the device is isolated and not on any network. When a networkless master does join a network, it will defer to any masters already on the network, or continue to maintain the timeline it made up during its networkless state if no other masters are detected. Attempting to force a client into master mode while it is actively bound to a network will fail with the status code {@link #ERROR}

return
{@link #SUCCESS} in case of success, {@link #ERROR} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        android.os.Parcel data  = android.os.Parcel.obtain();
        android.os.Parcel reply = android.os.Parcel.obtain();

        try {
            data.writeInterfaceToken(mInterfaceDesc);
            mRemote.transact(METHOD_FORCE_NETWORKLESS_MASTER_MODE, data, reply, 0);

            return reply.readInt();
        }
        catch (RemoteException e) {
            return ERROR_DEAD_OBJECT;
        }
        finally {
            reply.recycle();
            data.recycle();
        }
    
public booleangetAutoDisable()
Gets the current state of the common time service's auto disable flag.

return
The current state of the common time service's auto disable flag.
throws
android.os.RemoteException

        throwOnDeadServer();
        return (1 == mUtils.transactGetInt(METHOD_GET_AUTO_DISABLE, 1));
    
public intgetClientSyncInterval()
Gets the amount of time the common time service will wait between time synchronization requests when it is the client of another common time service on the network.

return
The time (in milliseconds) between time sync requests.
throws
android.os.RemoteException

        throwOnDeadServer();
        return mUtils.transactGetInt(METHOD_GET_CLIENT_SYNC_INTERVAL, -1);
    
public java.lang.StringgetInterfaceBinding()
Gets the name of the network interface which the common time service attempts to bind to.

return
a string with the network interface name which the common time service is bound to, or null if the service is currently unbound. Examples of interface names are things like "eth0", or "wlan0".
throws
android.os.RemoteException

        throwOnDeadServer();

        String ifaceName = mUtils.transactGetString(METHOD_GET_INTERFACE_BINDING, null);

        if ((null != ifaceName) && (0 == ifaceName.length()))
                return null;

        return ifaceName;
    
public intgetMasterAnnounceInterval()
Gets the amount of time the common time service will wait between master announcements when it is the timeline master.

return
The time (in milliseconds) between master announcements.
throws
android.os.RemoteException

        throwOnDeadServer();
        return mUtils.transactGetInt(METHOD_GET_MASTER_ANNOUNCE_INTERVAL, -1);
    
public java.net.InetSocketAddressgetMasterElectionEndpoint()
Gets the IP endpoint used by the time service to participate in the master election protocol.

return
an InetSocketAddress containing the IP address and UDP port being used by the system's common time service to participate in the master election protocol.
throws
android.os.RemoteException

        throwOnDeadServer();
        return mUtils.transactGetSockaddr(METHOD_GET_MASTER_ELECTION_ENDPOINT);
    
public longgetMasterElectionGroupId()
Gets the current group ID used by the common time service in the master election protocol.

return
The 64-bit group ID of the common time service.
throws
android.os.RemoteException

        throwOnDeadServer();
        return mUtils.transactGetLong(METHOD_GET_MASTER_ELECTION_GROUP_ID, INVALID_GROUP_ID);
    
public bytegetMasterElectionPriority()
Gets the current priority of the common time service used in the master election protocol.

return
an 8 bit value indicating the priority of this common time service relative to other common time services operating in the same domain.
throws
android.os.RemoteException

        throwOnDeadServer();
        return (byte)mUtils.transactGetInt(METHOD_GET_MASTER_ELECTION_PRIORITY, -1);
    
public intgetPanicThreshold()
Gets the panic threshold for the estimated error level of the common time service. When the common time service's estimated error rises above this level, the service will panic and reset, causing a discontinuity in the currently synchronized timeline.

return
The threshold (in microseconds) past which the common time service will panic.
throws
android.os.RemoteException

        throwOnDeadServer();
        return mUtils.transactGetInt(METHOD_GET_PANIC_THRESHOLD, -1);
    
public voidrelease()
Release all native resources held by this {@link android.os.CommonTimeConfig} instance. Once resources have been released, the {@link android.os.CommonTimeConfig} instance is disconnected from the native service and will throw a {@link android.os.RemoteException} if any of its methods are called. Clients should always call release on their client instances before releasing their last Java reference to the instance. Failure to do this will cause non-deterministic native resource reclamation and may cause the common time service to remain active on the network for longer than it should.

        if (null != mRemote) {
            try {
                mRemote.unlinkToDeath(mDeathHandler, 0);
            }
            catch (NoSuchElementException e) { }
            mRemote = null;
        }
        mUtils = null;
    
public intsetAutoDisable(boolean autoDisable)
Sets the current state of the common time service's auto disable flag. When the time service's auto disable flag is set, it will automatically cease all network activity when it has no active local clients, resuming activity the next time the service has interested local clients. When the auto disabled flag is cleared, the common time service will continue to participate the time synchronization group even when it has no active local clients.

param
autoDisable The desired state of the common time service's auto disable flag.
return
{@link #SUCCESS} in case of success, {@link #ERROR} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;

        return mUtils.transactSetInt(METHOD_SET_AUTO_DISABLE, autoDisable ? 1 : 0);
    
public intsetClientSyncInterval(int interval)
Sets the amount of time the common time service will wait between time synchronization requests when it is the client of another common time service on the network.

param
interval The time (in milliseconds) between time sync requests.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetInt(METHOD_SET_CLIENT_SYNC_INTERVAL, interval);
    
public intsetMasterAnnounceInterval(int interval)
Sets the amount of time the common time service will wait between master announcements when it is the timeline master.

param
interval The time (in milliseconds) between master announcements.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetInt(METHOD_SET_MASTER_ANNOUNCE_INTERVAL, interval);
    
public intsetMasterElectionEndpoint(java.net.InetSocketAddress ep)
Sets the IP endpoint used by the common time service to participate in the master election protocol.

param
ep The IP address and UDP port to be used by the common time service to participate in the master election protocol. The supplied IP address must be either the broadcast or multicast address, unicast addresses are considered to be illegal values.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetSockaddr(METHOD_SET_MASTER_ELECTION_ENDPOINT, ep);
    
public intsetMasterElectionGroupId(long id)
Sets the current group ID used by the common time service in the master election protocol.

param
id The 64-bit group ID of the common time service.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetLong(METHOD_SET_MASTER_ELECTION_GROUP_ID, id);
    
public intsetMasterElectionPriority(byte priority)
Sets the current priority of the common time service used in the master election protocol.

param
priority priority of the common time service used in the master election protocol. Lower numbers are lower priority.
return
{@link #SUCCESS} in case of success, {@link #ERROR} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetInt(METHOD_SET_MASTER_ELECTION_PRIORITY, priority);
    
public intsetNetworkBinding(java.lang.String ifaceName)
Sets the name of the network interface which the common time service should attempt to bind to.

param
ifaceName The name of the network interface ("eth0", "wlan0", etc...) wich the common time service should attempt to bind to, or null to force the common time service to unbind from the network and run in networkless mode.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;

        return mUtils.transactSetString(METHOD_SET_INTERFACE_BINDING,
                                       (null == ifaceName) ? "" : ifaceName);
    
public intsetPanicThreshold(int threshold)
Sets the panic threshold for the estimated error level of the common time service. When the common time service's estimated error rises above this level, the service will panic and reset, causing a discontinuity in the currently synchronized timeline.

param
threshold The threshold (in microseconds) past which the common time service will panic.
return
{@link #SUCCESS} in case of success, {@link #ERROR}, {@link #ERROR_BAD_VALUE} or {@link #ERROR_DEAD_OBJECT} in case of failure.

        if (checkDeadServer())
            return ERROR_DEAD_OBJECT;
        return mUtils.transactSetInt(METHOD_SET_PANIC_THRESHOLD, threshold);
    
public voidsetServerDiedListener(android.os.CommonTimeConfig$OnServerDiedListener listener)
Registers an OnServerDiedListener interface.

Call this method with a null listener to stop receiving server death notifications.

        synchronized (mListenerLock) {
            mServerDiedListener = listener;
        }
    
private voidthrowOnDeadServer()

        if (checkDeadServer())
            throw new RemoteException();