diff options
| author | Neil Fuller <nfuller@google.com> | 2018-06-04 15:35:31 +0100 |
|---|---|---|
| committer | Neil Fuller <nfuller@google.com> | 2018-06-04 19:26:29 +0100 |
| commit | ea8a738581ee842d14656e4904a911064d79c228 (patch) | |
| tree | a1ffdbefb22b9465dd0fddfe5a830a4d80da2e9a /core/java/android | |
| parent | 22e64ec6116c16b550c51ecafaea31510db97b55 (diff) | |
Remove CommonClock / CommonTimeManagementService
The service and associated code is unused.
Bug: 80462439
Test: build / boot
Change-Id: Ibdfab1b7d2951a0c45e07bd47850af037990841b
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/CommonClock.java | 405 | ||||
| -rw-r--r-- | core/java/android/os/CommonTimeConfig.java | 447 | ||||
| -rw-r--r-- | core/java/android/os/CommonTimeUtils.java | 293 |
3 files changed, 0 insertions, 1145 deletions
diff --git a/core/java/android/os/CommonClock.java b/core/java/android/os/CommonClock.java deleted file mode 100644 index 2ecf317c2d09..000000000000 --- a/core/java/android/os/CommonClock.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (C) 2012 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 android.os; - -import java.net.InetSocketAddress; -import java.util.NoSuchElementException; -import android.os.Binder; -import android.os.CommonTimeUtils; -import android.os.IBinder; -import android.os.Parcel; -import android.os.RemoteException; -import android.os.ServiceManager; - -/** - * Used for accessing the android common time service's common clock and receiving notifications - * about common time synchronization status changes. - * @hide - */ -public class CommonClock { - /** - * Sentinel value returned by {@link #getTime()} and {@link #getEstimatedError()} when the - * common time service is not able to determine the current common time due to a lack of - * synchronization. - */ - public static final long TIME_NOT_SYNCED = -1; - - /** - * Sentinel value returned by {@link #getTimelineId()} when the common time service is not - * currently synced to any timeline. - */ - public static final long INVALID_TIMELINE_ID = 0; - - /** - * Sentinel value returned by {@link #getEstimatedError()} when the common time service is not - * currently synced to any timeline. - */ - public static final int ERROR_ESTIMATE_UNKNOWN = 0x7FFFFFFF; - - /** - * Value used by {@link #getState()} to indicate that there was an internal error while - * attempting to determine the state of the common time service. - */ - public static final int STATE_INVALID = -1; - - /** - * Value used by {@link #getState()} to indicate that the common time service is in its initial - * state and attempting to find the current timeline master, if any. The service will - * transition to either {@link #STATE_CLIENT} if it finds an active master, or to - * {@link #STATE_MASTER} if no active master is found and this client becomes the master of a - * new timeline. - */ - public static final int STATE_INITIAL = 0; - - /** - * Value used by {@link #getState()} to indicate that the common time service is in its client - * state and is synchronizing its time to a different timeline master on the network. - */ - public static final int STATE_CLIENT = 1; - - /** - * Value used by {@link #getState()} to indicate that the common time service is in its master - * state and is serving as the timeline master for other common time service clients on the - * network. - */ - public static final int STATE_MASTER = 2; - - /** - * Value used by {@link #getState()} to indicate that the common time service is in its Ronin - * state. Common time service instances in the client state enter the Ronin state after their - * timeline master becomes unreachable on the network. Common time services who enter the Ronin - * state will begin a new master election for the timeline they were recently clients of. As - * clients detect they are not the winner and drop out of the election, they will transition to - * the {@link #STATE_WAIT_FOR_ELECTION} state. When there is only one client remaining in the - * election, it will assume ownership of the timeline and transition to the - * {@link #STATE_MASTER} state. During the election, all clients will allow their timeline to - * drift without applying correction. - */ - public static final int STATE_RONIN = 3; - - /** - * Value used by {@link #getState()} to indicate that the common time service is waiting for a - * master election to conclude and for the new master to announce itself before transitioning to - * the {@link #STATE_CLIENT} state. If no new master announces itself within the timeout - * threshold, the time service will transition back to the {@link #STATE_RONIN} state in order - * to restart the election. - */ - public static final int STATE_WAIT_FOR_ELECTION = 4; - - /** - * Name of the underlying native binder service - */ - public static final String SERVICE_NAME = "common_time.clock"; - - /** - * Class constructor. - * @throws android.os.RemoteException - */ - public CommonClock() - throws RemoteException { - mRemote = ServiceManager.getService(SERVICE_NAME); - if (null == mRemote) - throw new RemoteException(); - - mInterfaceDesc = mRemote.getInterfaceDescriptor(); - mUtils = new CommonTimeUtils(mRemote, mInterfaceDesc); - mRemote.linkToDeath(mDeathHandler, 0); - registerTimelineChangeListener(); - } - - /** - * Handy class factory method. - */ - static public CommonClock create() { - CommonClock retVal; - - try { - retVal = new CommonClock(); - } - catch (RemoteException e) { - retVal = null; - } - - return retVal; - } - - /** - * Release all native resources held by this {@link android.os.CommonClock} instance. Once - * resources have been released, the {@link android.os.CommonClock} 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. - */ - public void release() { - unregisterTimelineChangeListener(); - if (null != mRemote) { - try { - mRemote.unlinkToDeath(mDeathHandler, 0); - } - catch (NoSuchElementException e) { } - mRemote = null; - } - mUtils = null; - } - - /** - * Gets the common clock's current time. - * - * @return a signed 64-bit value representing the current common time in microseconds, or the - * special value {@link #TIME_NOT_SYNCED} if the common time service is currently not - * synchronized. - * @throws android.os.RemoteException - */ - public long getTime() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetLong(METHOD_GET_COMMON_TIME, TIME_NOT_SYNCED); - } - - /** - * Gets the current estimation of common clock's synchronization accuracy from the common time - * service. - * - * @return a signed 32-bit value representing the common time service's estimation of - * synchronization accuracy in microseconds, or the special value - * {@link #ERROR_ESTIMATE_UNKNOWN} if the common time service is currently not synchronized. - * Negative values indicate that the local server estimates that the nominal common time is - * behind the local server's time (in other words, the local clock is running fast) Positive - * values indicate that the local server estimates that the nominal common time is ahead of the - * local server's time (in other words, the local clock is running slow) - * @throws android.os.RemoteException - */ - public int getEstimatedError() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetInt(METHOD_GET_ESTIMATED_ERROR, ERROR_ESTIMATE_UNKNOWN); - } - - /** - * Gets the ID of the timeline the common time service is currently synchronizing its clock to. - * - * @return a long representing the unique ID of the timeline the common time service is - * currently synchronizing with, or {@link #INVALID_TIMELINE_ID} if the common time service is - * currently not synchronized. - * @throws android.os.RemoteException - */ - public long getTimelineId() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetLong(METHOD_GET_TIMELINE_ID, INVALID_TIMELINE_ID); - } - - /** - * Gets the current state of this clock's common time service in the the master election - * algorithm. - * - * @return a integer indicating the current state of the this clock's common time service in the - * master election algorithm or {@link #STATE_INVALID} if there is an internal error. - * @throws android.os.RemoteException - */ - public int getState() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetInt(METHOD_GET_STATE, STATE_INVALID); - } - - /** - * Gets the IP address and UDP port of the current timeline master. - * - * @return an InetSocketAddress containing the IP address and UDP port of the current timeline - * master, or null if there is no current master. - * @throws android.os.RemoteException - */ - public InetSocketAddress getMasterAddr() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetSockaddr(METHOD_GET_MASTER_ADDRESS); - } - - /** - * The OnTimelineChangedListener interface defines a method called by the - * {@link android.os.CommonClock} instance to indicate that the time synchronization service has - * either synchronized with a new timeline, or is no longer a member of any timeline. The - * client application can implement this interface and register the listener with the - * {@link #setTimelineChangedListener(OnTimelineChangedListener)} method. - */ - public interface OnTimelineChangedListener { - /** - * Method called when the time service's timeline has changed. - * - * @param newTimelineId a long which uniquely identifies the timeline the time - * synchronization service is now a member of, or {@link #INVALID_TIMELINE_ID} if the the - * service is not synchronized to any timeline. - */ - void onTimelineChanged(long newTimelineId); - } - - /** - * Registers an OnTimelineChangedListener interface. - * <p>Call this method with a null listener to stop receiving server death notifications. - */ - public void setTimelineChangedListener(OnTimelineChangedListener listener) { - synchronized (mListenerLock) { - mTimelineChangedListener = listener; - } - } - - /** - * The OnServerDiedListener interface defines a method called by the - * {@link android.os.CommonClock} instance to indicate that the connection to the native media - * server has been broken and that the {@link android.os.CommonClock} instance will need to be - * released and re-created. The client application can implement this interface and register - * the listener with the {@link #setServerDiedListener(OnServerDiedListener)} method. - */ - public interface OnServerDiedListener { - /** - * Method called when the native media server has died. <p>If the native common time - * service encounters a fatal error and needs to restart, the binder connection from the - * {@link android.os.CommonClock} instance to the common time service will be broken. To - * restore functionality, clients should {@link #release()} their old visualizer and create - * a new instance. - */ - void onServerDied(); - } - - /** - * Registers an OnServerDiedListener interface. - * <p>Call this method with a null listener to stop receiving server death notifications. - */ - public void setServerDiedListener(OnServerDiedListener listener) { - synchronized (mListenerLock) { - mServerDiedListener = listener; - } - } - - protected void finalize() throws Throwable { release(); } - - private void throwOnDeadServer() throws RemoteException { - if ((null == mRemote) || (null == mUtils)) - throw new RemoteException(); - } - - private final Object mListenerLock = new Object(); - private OnTimelineChangedListener mTimelineChangedListener = null; - private OnServerDiedListener mServerDiedListener = null; - - private IBinder mRemote = null; - private String mInterfaceDesc = ""; - private CommonTimeUtils mUtils; - - private IBinder.DeathRecipient mDeathHandler = new IBinder.DeathRecipient() { - public void binderDied() { - synchronized (mListenerLock) { - if (null != mServerDiedListener) - mServerDiedListener.onServerDied(); - } - } - }; - - private class TimelineChangedListener extends Binder { - @Override - protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) - throws RemoteException { - switch (code) { - case METHOD_CBK_ON_TIMELINE_CHANGED: - data.enforceInterface(DESCRIPTOR); - long timelineId = data.readLong(); - synchronized (mListenerLock) { - if (null != mTimelineChangedListener) - mTimelineChangedListener.onTimelineChanged(timelineId); - } - return true; - } - - return super.onTransact(code, data, reply, flags); - } - - private static final String DESCRIPTOR = "android.os.ICommonClockListener"; - }; - - private TimelineChangedListener mCallbackTgt = null; - - private void registerTimelineChangeListener() throws RemoteException { - if (null != mCallbackTgt) - return; - - boolean success = false; - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - mCallbackTgt = new TimelineChangedListener(); - - try { - data.writeInterfaceToken(mInterfaceDesc); - data.writeStrongBinder(mCallbackTgt); - mRemote.transact(METHOD_REGISTER_LISTENER, data, reply, 0); - success = (0 == reply.readInt()); - } - catch (RemoteException e) { - success = false; - } - finally { - reply.recycle(); - data.recycle(); - } - - // Did we catch a remote exception or fail to register our callback target? If so, our - // object must already be dead (or be as good as dead). Clear out all of our state so that - // our other methods will properly indicate a dead object. - if (!success) { - mCallbackTgt = null; - mRemote = null; - mUtils = null; - } - } - - private void unregisterTimelineChangeListener() { - if (null == mCallbackTgt) - return; - - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - - try { - data.writeInterfaceToken(mInterfaceDesc); - data.writeStrongBinder(mCallbackTgt); - mRemote.transact(METHOD_UNREGISTER_LISTENER, data, reply, 0); - } - catch (RemoteException e) { } - finally { - reply.recycle(); - data.recycle(); - mCallbackTgt = null; - } - } - - private static final int METHOD_IS_COMMON_TIME_VALID = IBinder.FIRST_CALL_TRANSACTION; - private static final int METHOD_COMMON_TIME_TO_LOCAL_TIME = METHOD_IS_COMMON_TIME_VALID + 1; - private static final int METHOD_LOCAL_TIME_TO_COMMON_TIME = METHOD_COMMON_TIME_TO_LOCAL_TIME + 1; - private static final int METHOD_GET_COMMON_TIME = METHOD_LOCAL_TIME_TO_COMMON_TIME + 1; - private static final int METHOD_GET_COMMON_FREQ = METHOD_GET_COMMON_TIME + 1; - private static final int METHOD_GET_LOCAL_TIME = METHOD_GET_COMMON_FREQ + 1; - private static final int METHOD_GET_LOCAL_FREQ = METHOD_GET_LOCAL_TIME + 1; - private static final int METHOD_GET_ESTIMATED_ERROR = METHOD_GET_LOCAL_FREQ + 1; - private static final int METHOD_GET_TIMELINE_ID = METHOD_GET_ESTIMATED_ERROR + 1; - private static final int METHOD_GET_STATE = METHOD_GET_TIMELINE_ID + 1; - private static final int METHOD_GET_MASTER_ADDRESS = METHOD_GET_STATE + 1; - private static final int METHOD_REGISTER_LISTENER = METHOD_GET_MASTER_ADDRESS + 1; - private static final int METHOD_UNREGISTER_LISTENER = METHOD_REGISTER_LISTENER + 1; - - private static final int METHOD_CBK_ON_TIMELINE_CHANGED = IBinder.FIRST_CALL_TRANSACTION; -} diff --git a/core/java/android/os/CommonTimeConfig.java b/core/java/android/os/CommonTimeConfig.java deleted file mode 100644 index 1f9fab5eb73d..000000000000 --- a/core/java/android/os/CommonTimeConfig.java +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2012 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 android.os; - -import java.net.InetSocketAddress; -import java.util.NoSuchElementException; - -import android.os.CommonTimeUtils; -import android.os.IBinder; -import android.os.RemoteException; -import android.os.ServiceManager; - -/** - * Used for configuring and controlling the status of the android common time service. - * @hide - */ -public class CommonTimeConfig { - /** - * Successful operation. - */ - public static final int SUCCESS = 0; - /** - * Unspecified error. - */ - public static final int ERROR = -1; - /** - * Operation failed due to bad parameter value. - */ - public static final int ERROR_BAD_VALUE = -4; - /** - * Operation failed due to dead remote object. - */ - public static final int ERROR_DEAD_OBJECT = -7; - - /** - * Sentinel value returned by {@link #getMasterElectionGroupId()} when an error occurs trying to - * fetch the master election group. - */ - public static final long INVALID_GROUP_ID = -1; - - /** - * Name of the underlying native binder service - */ - public static final String SERVICE_NAME = "common_time.config"; - - /** - * Class constructor. - * @throws android.os.RemoteException - */ - public CommonTimeConfig() - throws RemoteException { - mRemote = ServiceManager.getService(SERVICE_NAME); - if (null == mRemote) - throw new RemoteException(); - - mInterfaceDesc = mRemote.getInterfaceDescriptor(); - mUtils = new CommonTimeUtils(mRemote, mInterfaceDesc); - mRemote.linkToDeath(mDeathHandler, 0); - } - - /** - * Handy class factory method. - */ - static public CommonTimeConfig create() { - CommonTimeConfig retVal; - - try { - retVal = new CommonTimeConfig(); - } - catch (RemoteException e) { - retVal = null; - } - - return retVal; - } - - /** - * 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. - */ - public void release() { - if (null != mRemote) { - try { - mRemote.unlinkToDeath(mDeathHandler, 0); - } - catch (NoSuchElementException e) { } - mRemote = null; - } - mUtils = null; - } - - /** - * 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 - */ - public byte getMasterElectionPriority() - throws RemoteException { - throwOnDeadServer(); - return (byte)mUtils.transactGetInt(METHOD_GET_MASTER_ELECTION_PRIORITY, -1); - } - - /** - * 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. - */ - public int setMasterElectionPriority(byte priority) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetInt(METHOD_SET_MASTER_ELECTION_PRIORITY, priority); - } - - /** - * 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 - */ - public InetSocketAddress getMasterElectionEndpoint() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetSockaddr(METHOD_GET_MASTER_ELECTION_ENDPOINT); - } - - /** - * 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. - */ - public int setMasterElectionEndpoint(InetSocketAddress ep) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetSockaddr(METHOD_SET_MASTER_ELECTION_ENDPOINT, ep); - } - - /** - * 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 - */ - public long getMasterElectionGroupId() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetLong(METHOD_GET_MASTER_ELECTION_GROUP_ID, INVALID_GROUP_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. - */ - public int setMasterElectionGroupId(long id) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetLong(METHOD_SET_MASTER_ELECTION_GROUP_ID, id); - } - - /** - * 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 - */ - public String getInterfaceBinding() - throws RemoteException { - throwOnDeadServer(); - - String ifaceName = mUtils.transactGetString(METHOD_GET_INTERFACE_BINDING, null); - - if ((null != ifaceName) && (0 == ifaceName.length())) - return null; - - return 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. - */ - public int setNetworkBinding(String ifaceName) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - - return mUtils.transactSetString(METHOD_SET_INTERFACE_BINDING, - (null == ifaceName) ? "" : ifaceName); - } - - /** - * 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 - */ - public int getMasterAnnounceInterval() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetInt(METHOD_GET_MASTER_ANNOUNCE_INTERVAL, -1); - } - - /** - * 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. - */ - public int setMasterAnnounceInterval(int interval) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetInt(METHOD_SET_MASTER_ANNOUNCE_INTERVAL, interval); - } - - /** - * 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 - */ - public int getClientSyncInterval() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetInt(METHOD_GET_CLIENT_SYNC_INTERVAL, -1); - } - - /** - * 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. - */ - public int setClientSyncInterval(int interval) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetInt(METHOD_SET_CLIENT_SYNC_INTERVAL, interval); - } - - /** - * 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 - */ - public int getPanicThreshold() - throws RemoteException { - throwOnDeadServer(); - return mUtils.transactGetInt(METHOD_GET_PANIC_THRESHOLD, -1); - } - - /** - * 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. - */ - public int setPanicThreshold(int threshold) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - return mUtils.transactSetInt(METHOD_SET_PANIC_THRESHOLD, threshold); - } - - /** - * 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 - */ - public boolean getAutoDisable() - throws RemoteException { - throwOnDeadServer(); - return (1 == mUtils.transactGetInt(METHOD_GET_AUTO_DISABLE, 1)); - } - - /** - * 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. - */ - public int setAutoDisable(boolean autoDisable) { - if (checkDeadServer()) - return ERROR_DEAD_OBJECT; - - return mUtils.transactSetInt(METHOD_SET_AUTO_DISABLE, autoDisable ? 1 : 0); - } - - /** - * 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. - */ - public int forceNetworklessMasterMode() { - 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(); - } - } - - /** - * The OnServerDiedListener interface defines a method called by the - * {@link android.os.CommonTimeConfig} instance to indicate that the connection to the native - * media server has been broken and that the {@link android.os.CommonTimeConfig} instance will - * need to be released and re-created. The client application can implement this interface and - * register the listener with the {@link #setServerDiedListener(OnServerDiedListener)} method. - */ - public interface OnServerDiedListener { - /** - * Method called when the native common time service has died. <p>If the native common time - * service encounters a fatal error and needs to restart, the binder connection from the - * {@link android.os.CommonTimeConfig} instance to the common time service will be broken. - */ - void onServerDied(); - } - - /** - * Registers an OnServerDiedListener interface. - * <p>Call this method with a null listener to stop receiving server death notifications. - */ - public void setServerDiedListener(OnServerDiedListener listener) { - synchronized (mListenerLock) { - mServerDiedListener = listener; - } - } - - protected void finalize() throws Throwable { release(); } - - private boolean checkDeadServer() { - return ((null == mRemote) || (null == mUtils)); - } - - private void throwOnDeadServer() throws RemoteException { - if (checkDeadServer()) - throw new RemoteException(); - } - - private final Object mListenerLock = new Object(); - private OnServerDiedListener mServerDiedListener = null; - - private IBinder mRemote = null; - private String mInterfaceDesc = ""; - private CommonTimeUtils mUtils; - - private IBinder.DeathRecipient mDeathHandler = new IBinder.DeathRecipient() { - public void binderDied() { - synchronized (mListenerLock) { - if (null != mServerDiedListener) - mServerDiedListener.onServerDied(); - } - } - }; - - private static final int METHOD_GET_MASTER_ELECTION_PRIORITY = IBinder.FIRST_CALL_TRANSACTION; - private static final int METHOD_SET_MASTER_ELECTION_PRIORITY = METHOD_GET_MASTER_ELECTION_PRIORITY + 1; - private static final int METHOD_GET_MASTER_ELECTION_ENDPOINT = METHOD_SET_MASTER_ELECTION_PRIORITY + 1; - private static final int METHOD_SET_MASTER_ELECTION_ENDPOINT = METHOD_GET_MASTER_ELECTION_ENDPOINT + 1; - private static final int METHOD_GET_MASTER_ELECTION_GROUP_ID = METHOD_SET_MASTER_ELECTION_ENDPOINT + 1; - private static final int METHOD_SET_MASTER_ELECTION_GROUP_ID = METHOD_GET_MASTER_ELECTION_GROUP_ID + 1; - private static final int METHOD_GET_INTERFACE_BINDING = METHOD_SET_MASTER_ELECTION_GROUP_ID + 1; - private static final int METHOD_SET_INTERFACE_BINDING = METHOD_GET_INTERFACE_BINDING + 1; - private static final int METHOD_GET_MASTER_ANNOUNCE_INTERVAL = METHOD_SET_INTERFACE_BINDING + 1; - private static final int METHOD_SET_MASTER_ANNOUNCE_INTERVAL = METHOD_GET_MASTER_ANNOUNCE_INTERVAL + 1; - private static final int METHOD_GET_CLIENT_SYNC_INTERVAL = METHOD_SET_MASTER_ANNOUNCE_INTERVAL + 1; - private static final int METHOD_SET_CLIENT_SYNC_INTERVAL = METHOD_GET_CLIENT_SYNC_INTERVAL + 1; - private static final int METHOD_GET_PANIC_THRESHOLD = METHOD_SET_CLIENT_SYNC_INTERVAL + 1; - private static final int METHOD_SET_PANIC_THRESHOLD = METHOD_GET_PANIC_THRESHOLD + 1; - private static final int METHOD_GET_AUTO_DISABLE = METHOD_SET_PANIC_THRESHOLD + 1; - private static final int METHOD_SET_AUTO_DISABLE = METHOD_GET_AUTO_DISABLE + 1; - private static final int METHOD_FORCE_NETWORKLESS_MASTER_MODE = METHOD_SET_AUTO_DISABLE + 1; -} diff --git a/core/java/android/os/CommonTimeUtils.java b/core/java/android/os/CommonTimeUtils.java deleted file mode 100644 index ba060b87567e..000000000000 --- a/core/java/android/os/CommonTimeUtils.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (C) 2012 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 android.os; - -import java.net.InetAddress; -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetSocketAddress; -import java.util.Locale; -import static android.system.OsConstants.*; - -class CommonTimeUtils { - /** - * Successful operation. - */ - public static final int SUCCESS = 0; - /** - * Unspecified error. - */ - public static final int ERROR = -1; - /** - * Operation failed due to bad parameter value. - */ - public static final int ERROR_BAD_VALUE = -4; - /** - * Operation failed due to dead remote object. - */ - public static final int ERROR_DEAD_OBJECT = -7; - - public CommonTimeUtils(IBinder remote, String interfaceDesc) { - mRemote = remote; - mInterfaceDesc = interfaceDesc; - } - - public int transactGetInt(int method_code, int error_ret_val) - throws RemoteException { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - int ret_val; - - try { - int res; - data.writeInterfaceToken(mInterfaceDesc); - mRemote.transact(method_code, data, reply, 0); - - res = reply.readInt(); - ret_val = (0 == res) ? reply.readInt() : error_ret_val; - } - finally { - reply.recycle(); - data.recycle(); - } - - return ret_val; - } - - public int transactSetInt(int method_code, int val) { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - - try { - data.writeInterfaceToken(mInterfaceDesc); - data.writeInt(val); - mRemote.transact(method_code, data, reply, 0); - - return reply.readInt(); - } - catch (RemoteException e) { - return ERROR_DEAD_OBJECT; - } - finally { - reply.recycle(); - data.recycle(); - } - } - - public long transactGetLong(int method_code, long error_ret_val) - throws RemoteException { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - long ret_val; - - try { - int res; - data.writeInterfaceToken(mInterfaceDesc); - mRemote.transact(method_code, data, reply, 0); - - res = reply.readInt(); - ret_val = (0 == res) ? reply.readLong() : error_ret_val; - } - finally { - reply.recycle(); - data.recycle(); - } - - return ret_val; - } - - public int transactSetLong(int method_code, long val) { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - - try { - data.writeInterfaceToken(mInterfaceDesc); - data.writeLong(val); - mRemote.transact(method_code, data, reply, 0); - - return reply.readInt(); - } - catch (RemoteException e) { - return ERROR_DEAD_OBJECT; - } - finally { - reply.recycle(); - data.recycle(); - } - } - - public String transactGetString(int method_code, String error_ret_val) - throws RemoteException { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - String ret_val; - - try { - int res; - data.writeInterfaceToken(mInterfaceDesc); - mRemote.transact(method_code, data, reply, 0); - - res = reply.readInt(); - ret_val = (0 == res) ? reply.readString() : error_ret_val; - } - finally { - reply.recycle(); - data.recycle(); - } - - return ret_val; - } - - public int transactSetString(int method_code, String val) { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - - try { - data.writeInterfaceToken(mInterfaceDesc); - data.writeString(val); - mRemote.transact(method_code, data, reply, 0); - - return reply.readInt(); - } - catch (RemoteException e) { - return ERROR_DEAD_OBJECT; - } - finally { - reply.recycle(); - data.recycle(); - } - } - - public InetSocketAddress transactGetSockaddr(int method_code) - throws RemoteException { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - InetSocketAddress ret_val = null; - - try { - int res; - data.writeInterfaceToken(mInterfaceDesc); - mRemote.transact(method_code, data, reply, 0); - - res = reply.readInt(); - if (0 == res) { - int type; - int port = 0; - String addrStr = null; - - type = reply.readInt(); - - if (AF_INET == type) { - int addr = reply.readInt(); - port = reply.readInt(); - addrStr = String.format(Locale.US, "%d.%d.%d.%d", - (addr >> 24) & 0xFF, - (addr >> 16) & 0xFF, - (addr >> 8) & 0xFF, - addr & 0xFF); - } else if (AF_INET6 == type) { - int addr1 = reply.readInt(); - int addr2 = reply.readInt(); - int addr3 = reply.readInt(); - int addr4 = reply.readInt(); - - port = reply.readInt(); - - int flowinfo = reply.readInt(); - int scope_id = reply.readInt(); - - addrStr = String.format(Locale.US, "[%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X]", - (addr1 >> 16) & 0xFFFF, addr1 & 0xFFFF, - (addr2 >> 16) & 0xFFFF, addr2 & 0xFFFF, - (addr3 >> 16) & 0xFFFF, addr3 & 0xFFFF, - (addr4 >> 16) & 0xFFFF, addr4 & 0xFFFF); - } - - if (null != addrStr) { - ret_val = new InetSocketAddress(addrStr, port); - } - } - } - finally { - reply.recycle(); - data.recycle(); - } - - return ret_val; - } - - public int transactSetSockaddr(int method_code, InetSocketAddress addr) { - android.os.Parcel data = android.os.Parcel.obtain(); - android.os.Parcel reply = android.os.Parcel.obtain(); - int ret_val = ERROR; - - try { - data.writeInterfaceToken(mInterfaceDesc); - - if (null == addr) { - data.writeInt(0); - } else { - data.writeInt(1); - final InetAddress a = addr.getAddress(); - final byte[] b = a.getAddress(); - final int p = addr.getPort(); - - if (a instanceof Inet4Address) { - int v4addr = (((int)b[0] & 0xFF) << 24) | - (((int)b[1] & 0xFF) << 16) | - (((int)b[2] & 0xFF) << 8) | - ((int)b[3] & 0xFF); - - data.writeInt(AF_INET); - data.writeInt(v4addr); - data.writeInt(p); - } else - if (a instanceof Inet6Address) { - int i; - Inet6Address v6 = (Inet6Address)a; - data.writeInt(AF_INET6); - for (i = 0; i < 4; ++i) { - int aword = (((int)b[(i*4) + 0] & 0xFF) << 24) | - (((int)b[(i*4) + 1] & 0xFF) << 16) | - (((int)b[(i*4) + 2] & 0xFF) << 8) | - ((int)b[(i*4) + 3] & 0xFF); - data.writeInt(aword); - } - data.writeInt(p); - data.writeInt(0); // flow info - data.writeInt(v6.getScopeId()); - } else { - return ERROR_BAD_VALUE; - } - } - - mRemote.transact(method_code, data, reply, 0); - ret_val = reply.readInt(); - } - catch (RemoteException e) { - ret_val = ERROR_DEAD_OBJECT; - } - finally { - reply.recycle(); - data.recycle(); - } - - return ret_val; - } - - private IBinder mRemote; - private String mInterfaceDesc; -}; |
