Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1374dfa0 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Add numerous wearable APIs

parent a5813321
Loading
Loading
Loading
Loading
Compare c43facae to 70419935
Original line number Diff line number Diff line
Subproject commit c43facae3dba6fcf4139c6a36e3a6f364d6db057
Subproject commit 704199355e1c6f8b14402e01063fbae7b187b35b
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright 2013-2015 µg Project Team
 *
 * 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.google.android.gms.common.data;

import com.google.android.gms.common.api.Releasable;

import org.microg.gms.common.PublicApi;

import java.util.Iterator;

/**
 * TODO
 */
@PublicApi
public abstract class DataBuffer<T> implements Releasable, Iterable<T> {

    private DataHolder dataHolder;

    @PublicApi(exclude = true)
    public DataBuffer(DataHolder dataHolder) {
        this.dataHolder = dataHolder;
    }

    /**
     * @deprecated use {@link #release()} instead
     */
    @Deprecated
    public final void close() {
        release();
    }

    /**
     * Get the item at the specified position. Note that the objects returned from subsequent
     * invocations of this method for the same position may not be identical objects, but will be
     * equal in value.
     *
     * @param position The position of the item to retrieve.
     * @return the item at {@code position} in this buffer.
     */
    public abstract T get(int position);

    public int getCount() {
        return dataHolder == null ? 0 : dataHolder.getCount();
    }

    /**
     * @deprecated {@link #release()} is idempotent, and so is safe to call multiple times
     */
    @Deprecated
    public boolean isClosed() {
        return false;
    }

    @Override
    public Iterator<T> iterator() {
        return null;
    }

    /**
     * Releases resources used by the buffer. This method is idempotent.
     */
    @Override
    public void release() {

    }

    /**
     * In order to use this one should correctly override setDataRow(int) in his DataBufferRef
     * implementation. Be careful: there will be single DataBufferRef while iterating.
     * If you are not sure - DO NOT USE this iterator.
     */
    public Iterator<T> singleRefIterator() {
        return null;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package org.microg.gms.common.api;

public interface ApiConnection {
    public void connect();
    void connect();

    public void disconnect();
    void disconnect();

    public boolean isConnected();
    boolean isConnected();

    boolean isConnecting();
}
+1 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi {
    }

    private interface Runnable {
        public void run(LocationClientImpl client) throws RemoteException;
        void run(LocationClientImpl client) throws RemoteException;
    }

}
+145 −0
Original line number Diff line number Diff line
@@ -16,5 +16,150 @@

package com.google.android.gms.wearable;

import android.net.Uri;
import android.os.ParcelFileDescriptor;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.data.Freezable;

import org.microg.gms.common.PublicApi;

import java.io.InputStream;

/**
 * Exposes an API for components to read or write data items and assets.
 * <p/>
 * A {@link DataItem} is synchronized across all devices in an Android Wear network. It is possible
 * to set data items while not connected to any nodes. Those data items will be synchronized when
 * the nodes eventually come online.
 * <p/>
 * Data items are private to the application that created them, and are only accessible by that
 * application on other nodes. They should generally be small in size, relying on assets for the
 * transfer of larger, more persistent data objects such as images.
 * <p/>
 * Each data item is identified by a URI, accessible with {@link DataItem#getUri()}, that indicates
 * the item's creator and path. Fully specified URIs follow the following format:
 * {@code wear://<node_id>/<path>}, where <node_id> is the node ID of the wearable node that
 * created the data item, and <path> is an application-defined path. This means that given a data
 * item's URI, calling {@link Uri#getHost()} will return the creator's node ID.
 * <p/>
 * In some of the methods below (such as {@link #getDataItems(GoogleApiClient, Uri)}), it is
 * possible to omit the node ID from the URI, and only leave a path. In that case, the URI may
 * refer to multiple data items, since multiple nodes may create data items with the same path.
 * Partially specified data item URIs follow the following format:
 * {@ocde wear:/<path>}
 * Note the single / after wear:.
 */
@PublicApi
public interface DataApi {
    /**
     * Registers a listener to receive data item changed and deleted events. This call should be
     * balanced with a call to {@link #removeListener(GoogleApiClient, DataListener)}, to avoid
     * leaking resources.
     * <p/>
     * The listener will be notified of changes initiated by this node.
     */
    PendingResult<Status> addListener(GoogleApiClient client, DataListener listener);

    /**
     * Removes all specified data items from the Android Wear network.
     * <p/>
     * If uri is fully specified, this method will delete at most one data item. If {@code uri}
     * contains no host, multiple data items may be deleted, since different nodes may create data
     * items with the same path. See {@link DataApi} for details of the URI format.
     */
    PendingResult<DeleteDataItemsResult> deleteDataItems(GoogleApiClient client, Uri uri);

    /**
     * Retrieves a single {@link DataItem} from the Android Wear network. A fully qualified URI
     * must be specified. The URI's host must be the ID of the node that created the item.
     * <p/>
     * See {@link DataApi} for details of the URI format.
     */
    PendingResult<DataItemResult> getDataItem(GoogleApiClient client, Uri uri);

    /**
     * Retrieves all data items from the Android Wear network.
     * <p/>
     * Callers must call {@link DataItemBuffer#release()} on the returned buffer when finished
     * processing results.
     */
    PendingResult<DataItemBuffer> getDataItems(GoogleApiClient client);

    /**
     * Retrieves all data items matching the provided URI, from the Android Wear network.
     * <p/>
     * The URI must contain a path. If {@code uri} is fully specified, at most one data item will
     * be returned. If uri contains no host, multiple data items may be returned, since different
     * nodes may create data items with the same path. See {@link DataApi} for details of the URI
     * format.
     * <p/>
     * Callers must call {@link DataItemBuffer#release()} on the returned buffer when finished
     * processing results.
     */
    PendingResult<DataItemBuffer> getDataItems(GoogleApiClient client, Uri uri);

    /**
     * Retrieves a {@link ParcelFileDescriptor} pointing at the bytes of an asset. Only assets
     * previously stored in a {@link DataItem} may be retrieved.
     */
    PendingResult<GetFdForAssetResult> getFdForAsset(GoogleApiClient client, DataItemAsset asset);

    /**
     * Retrieves a {@link ParcelFileDescriptor} pointing at the bytes of an asset. Only assets
     * previously stored in a {@link DataItem} may be retrieved.
     */
    PendingResult<GetFdForAssetResult> getFdForAsset(GoogleApiClient client, Asset asset);

    /**
     * Adds a {@link DataItem} to the Android Wear network. The updated item is synchronized across
     * all devices.
     */
    PendingResult<DataItemResult> putDataItem(GoogleApiClient client, PutDataRequest request);

    /**
     * Removes a data listener which was previously added through
     * {@link #addListener(GoogleApiClient, DataListener)}.
     */
    PendingResult<Status> removeListener(GoogleApiClient client, DataListener listener);

    interface DataItemResult extends Result {
        /**
         * @return data item, or {@code null} if the item does not exit.
         */
        DataItem getDataItem();
    }

    interface DataListener {
        /**
         * Notification that a set of data items have been changed or deleted. The data buffer is
         * released upon completion of this method. If a caller wishes to use the events outside
         * this callback, they should be sure to {@link Freezable#freeze()} the DataEvent objects
         * they wish to use.
         */
        void onDataChanged(DataEventBuffer dataEvents);
    }

    interface DeleteDataItemsResult extends Result {
        /**
         * @return the number of items deleted by
         * {@link DataApi#deleteDataItems(GoogleApiClient, Uri)}.
         */
        int getNumDeleted();
    }

    interface GetFdForAssetResult extends Result {
        /**
         * @return a file descriptor for the requested asset.
         */
        ParcelFileDescriptor getFd();

        /**
         * @return an input stream wrapping the file descriptor. When this input stream is closed, the file descriptor is, as well.
         */
        InputStream getInputStream();
    }
}
Loading