Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.media;
     18 
     19 import android.annotation.NonNull;
     20 import android.annotation.Nullable;
     21 import android.content.Context;
     22 import android.media.update.ApiLoader;
     23 import android.media.update.MediaSession2Provider;
     24 import android.os.Bundle;
     25 
     26 import java.util.Set;
     27 
     28 /**
     29  * @hide
     30  * Represent set of {@link SessionCommand2}.
     31  */
     32 public final class SessionCommandGroup2 {
     33     // TODO(jaewan): Rename and move provider
     34     private final MediaSession2Provider.CommandGroupProvider mProvider;
     35 
     36     public SessionCommandGroup2() {
     37         mProvider = ApiLoader.getProvider().createMediaSession2CommandGroup(this, null);
     38     }
     39 
     40     public SessionCommandGroup2(@Nullable SessionCommandGroup2 others) {
     41         mProvider = ApiLoader.getProvider().createMediaSession2CommandGroup(this, others);
     42     }
     43 
     44     /**
     45      * @hide
     46      */
     47     public SessionCommandGroup2(@NonNull MediaSession2Provider.CommandGroupProvider provider) {
     48         mProvider = provider;
     49     }
     50 
     51     public void addCommand(@NonNull SessionCommand2 command) {
     52         mProvider.addCommand_impl(command);
     53     }
     54 
     55     public void addCommand(int commandCode) {
     56         // TODO(jaewna): Implement
     57     }
     58 
     59     public void addAllPredefinedCommands() {
     60         mProvider.addAllPredefinedCommands_impl();
     61     }
     62 
     63     public void removeCommand(@NonNull SessionCommand2 command) {
     64         mProvider.removeCommand_impl(command);
     65     }
     66 
     67     public void removeCommand(int commandCode) {
     68         // TODO(jaewan): Implement.
     69     }
     70 
     71     public boolean hasCommand(@NonNull SessionCommand2 command) {
     72         return mProvider.hasCommand_impl(command);
     73     }
     74 
     75     public boolean hasCommand(int code) {
     76         return mProvider.hasCommand_impl(code);
     77     }
     78 
     79     public @NonNull
     80     Set<SessionCommand2> getCommands() {
     81         return mProvider.getCommands_impl();
     82     }
     83 
     84     /**
     85      * @hide
     86      */
     87     public @NonNull MediaSession2Provider.CommandGroupProvider getProvider() {
     88         return mProvider;
     89     }
     90 
     91     /**
     92      * @return new bundle from the CommandGroup
     93      * @hide
     94      */
     95     public @NonNull Bundle toBundle() {
     96         return mProvider.toBundle_impl();
     97     }
     98 
     99     /**
    100      * @return new instance of CommandGroup from the bundle
    101      * @hide
    102      */
    103     public static @Nullable SessionCommandGroup2 fromBundle(Bundle commands) {
    104         return ApiLoader.getProvider().fromBundle_MediaSession2CommandGroup(commands);
    105     }
    106 }
    107