Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dhina17
platform_frameworks_base
Commits
c2375d9b
Commit
c2375d9b
authored
7 years ago
by
TreeHugger Robot
Committed by
Android (Google) Code Review
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Fix docs and bug in SliceManager#bindSlice" into pi-dev
parents
fcbbb726
5ffacd06
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/java/android/app/slice/SliceManager.java
+48
-59
48 additions, 59 deletions
core/java/android/app/slice/SliceManager.java
with
48 additions
and
59 deletions
core/java/android/app/slice/SliceManager.java
+
48
−
59
View file @
c2375d9b
...
...
@@ -277,12 +277,12 @@ public class SliceManager {
* <ol>
* <li> If the intent contains data that {@link ContentResolver#getType} is
* {@link SliceProvider#SLICE_TYPE} then the data will be returned.</li>
* <li>If the intent with {@link #CATEGORY_SLICE} added resolves to a provider, then
* the provider will be asked to {@link SliceProvider#onMapIntentToUri} and that result
* will be returned.</li>
* <li>Lastly, if the intent explicitly points at an activity, and that activity has
* <li>If the intent explicitly points at an activity, and that activity has
* meta-data for key {@link #SLICE_METADATA_KEY}, then the Uri specified there will be
* returned.</li>
* <li>Lastly, if the intent with {@link #CATEGORY_SLICE} added resolves to a provider, then
* the provider will be asked to {@link SliceProvider#onMapIntentToUri} and that result
* will be returned.</li>
* <li>If no slice is found, then {@code null} is returned.</li>
* </ol>
* @param intent The intent associated with a slice.
...
...
@@ -292,37 +292,12 @@ public class SliceManager {
* @see Intent
*/
public
@Nullable
Uri
mapIntentToUri
(
@NonNull
Intent
intent
)
{
Preconditions
.
checkNotNull
(
intent
,
"intent"
);
Preconditions
.
checkArgument
(
intent
.
getComponent
()
!=
null
||
intent
.
getPackage
()
!=
null
||
intent
.
getData
()
!=
null
,
"Slice intent must be explicit %s"
,
intent
);
ContentResolver
resolver
=
mContext
.
getContentResolver
();
// Check if the intent has data for the slice uri on it and use that
final
Uri
intentData
=
intent
.
getData
();
if
(
intentData
!=
null
&&
SliceProvider
.
SLICE_TYPE
.
equals
(
resolver
.
getType
(
intentData
)))
{
return
intentData
;
}
final
Uri
staticUri
=
resolveStatic
(
intent
,
resolver
);
if
(
staticUri
!=
null
)
return
staticUri
;
// Otherwise ask the app
Intent
queryIntent
=
new
Intent
(
intent
);
if
(!
queryIntent
.
hasCategory
(
CATEGORY_SLICE
))
{
queryIntent
.
addCategory
(
CATEGORY_SLICE
);
}
List
<
ResolveInfo
>
providers
=
mContext
.
getPackageManager
().
queryIntentContentProviders
(
queryIntent
,
0
);
if
(
providers
==
null
||
providers
.
isEmpty
())
{
// There are no providers, see if this activity has a direct link.
ResolveInfo
resolve
=
mContext
.
getPackageManager
().
resolveActivity
(
intent
,
PackageManager
.
GET_META_DATA
);
if
(
resolve
!=
null
&&
resolve
.
activityInfo
!=
null
&&
resolve
.
activityInfo
.
metaData
!=
null
&&
resolve
.
activityInfo
.
metaData
.
containsKey
(
SLICE_METADATA_KEY
))
{
return
Uri
.
parse
(
resolve
.
activityInfo
.
metaData
.
getString
(
SLICE_METADATA_KEY
));
}
return
null
;
}
String
authority
=
providers
.
get
(
0
).
providerInfo
.
authority
;
String
authority
=
getAuthority
(
intent
);
if
(
authority
==
null
)
return
null
;
Uri
uri
=
new
Uri
.
Builder
().
scheme
(
ContentResolver
.
SCHEME_CONTENT
)
.
authority
(
authority
).
build
();
try
(
ContentProviderClient
provider
=
resolver
.
acquireContentProviderClient
(
uri
))
{
...
...
@@ -343,10 +318,43 @@ public class SliceManager {
}
}
private
String
getAuthority
(
Intent
intent
)
{
Intent
queryIntent
=
new
Intent
(
intent
);
if
(!
queryIntent
.
hasCategory
(
CATEGORY_SLICE
))
{
queryIntent
.
addCategory
(
CATEGORY_SLICE
);
}
List
<
ResolveInfo
>
providers
=
mContext
.
getPackageManager
().
queryIntentContentProviders
(
queryIntent
,
0
);
return
providers
!=
null
&&
!
providers
.
isEmpty
()
?
providers
.
get
(
0
).
providerInfo
.
authority
:
null
;
}
private
Uri
resolveStatic
(
@NonNull
Intent
intent
,
ContentResolver
resolver
)
{
Preconditions
.
checkNotNull
(
intent
,
"intent"
);
Preconditions
.
checkArgument
(
intent
.
getComponent
()
!=
null
||
intent
.
getPackage
()
!=
null
||
intent
.
getData
()
!=
null
,
"Slice intent must be explicit %s"
,
intent
);
// Check if the intent has data for the slice uri on it and use that
final
Uri
intentData
=
intent
.
getData
();
if
(
intentData
!=
null
&&
SliceProvider
.
SLICE_TYPE
.
equals
(
resolver
.
getType
(
intentData
)))
{
return
intentData
;
}
// There are no providers, see if this activity has a direct link.
ResolveInfo
resolve
=
mContext
.
getPackageManager
().
resolveActivity
(
intent
,
PackageManager
.
GET_META_DATA
);
if
(
resolve
!=
null
&&
resolve
.
activityInfo
!=
null
&&
resolve
.
activityInfo
.
metaData
!=
null
&&
resolve
.
activityInfo
.
metaData
.
containsKey
(
SLICE_METADATA_KEY
))
{
return
Uri
.
parse
(
resolve
.
activityInfo
.
metaData
.
getString
(
SLICE_METADATA_KEY
));
}
return
null
;
}
/**
* Turns a slice intent into slice content. Expects an explicit intent. If there is no
* {@link android.content.ContentProvider} associated with the given intent this will throw
* {@link IllegalArgumentException}.
* Turns a slice intent into slice content. Is a shortcut to perform the action
* of both {@link #mapIntentToUri(Intent)} and {@link #bindSlice(Uri, List)} at once.
*
* @param intent The intent associated with a slice.
* @param supportedSpecs List of supported specs.
...
...
@@ -362,28 +370,11 @@ public class SliceManager {
||
intent
.
getData
()
!=
null
,
"Slice intent must be explicit %s"
,
intent
);
ContentResolver
resolver
=
mContext
.
getContentResolver
();
// Check if the intent has data for the slice uri on it and use that
final
Uri
intentData
=
intent
.
getData
();
if
(
intentData
!=
null
&&
SliceProvider
.
SLICE_TYPE
.
equals
(
resolver
.
getType
(
intentData
)))
{
return
bindSlice
(
intentData
,
supportedSpecs
);
}
final
Uri
staticUri
=
resolveStatic
(
intent
,
resolver
);
if
(
staticUri
!=
null
)
return
bindSlice
(
staticUri
,
supportedSpecs
);
// Otherwise ask the app
List
<
ResolveInfo
>
providers
=
mContext
.
getPackageManager
().
queryIntentContentProviders
(
intent
,
0
);
if
(
providers
==
null
||
providers
.
isEmpty
())
{
// There are no providers, see if this activity has a direct link.
ResolveInfo
resolve
=
mContext
.
getPackageManager
().
resolveActivity
(
intent
,
PackageManager
.
GET_META_DATA
);
if
(
resolve
!=
null
&&
resolve
.
activityInfo
!=
null
&&
resolve
.
activityInfo
.
metaData
!=
null
&&
resolve
.
activityInfo
.
metaData
.
containsKey
(
SLICE_METADATA_KEY
))
{
return
bindSlice
(
Uri
.
parse
(
resolve
.
activityInfo
.
metaData
.
getString
(
SLICE_METADATA_KEY
)),
supportedSpecs
);
}
return
null
;
}
String
authority
=
providers
.
get
(
0
).
providerInfo
.
authority
;
String
authority
=
getAuthority
(
intent
);
if
(
authority
==
null
)
return
null
;
Uri
uri
=
new
Uri
.
Builder
().
scheme
(
ContentResolver
.
SCHEME_CONTENT
)
.
authority
(
authority
).
build
();
try
(
ContentProviderClient
provider
=
resolver
.
acquireContentProviderClient
(
uri
))
{
...
...
@@ -392,8 +383,6 @@ public class SliceManager {
}
Bundle
extras
=
new
Bundle
();
extras
.
putParcelable
(
SliceProvider
.
EXTRA_INTENT
,
intent
);
extras
.
putParcelableArrayList
(
SliceProvider
.
EXTRA_SUPPORTED_SPECS
,
new
ArrayList
<>(
supportedSpecs
));
final
Bundle
res
=
provider
.
call
(
SliceProvider
.
METHOD_MAP_INTENT
,
null
,
extras
);
if
(
res
==
null
)
{
return
null
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment